-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What the correct way to get statusCode for incoming data? #39
Comments
Hi @zebox! When nginx's proxy_read_timeout occur, it just closes both ends of connections – from browser and to your server. So the browser does not receive 1006 code really – it just handles connection close in such way. And, inside your loop you will not receive CloseFrame from nginx too – again, just because it simply close the connection. So what we expect your loop to receive is Could you run this simple example and put it behind your nginx with some proxy_read_timeout set? Something like this: package main
import (
"log"
"net"
"github.com/gobwas/ws"
"github.com/gobwas/ws/wsutil"
)
func main() {
ln, err := net.Listen("tcp", "localhost:8989")
if err != nil {
log.Fatal(err)
}
for {
conn, err := ln.Accept()
if err != nil {
log.Fatal(err)
}
name := conn.RemoteAddr().String()
log.Printf("accept from %s", name)
go func() {
_, err := ws.Upgrade(conn)
if err != nil {
log.Printf("upgrade %s error: %v", name, err)
}
log.Printf("upgrade %s ok", name)
for {
msgs, err := wsutil.ReadClientMessage(conn, nil)
if err != nil {
log.Printf("read message from %s error: %v", name, err)
return
}
for _, msg := range msgs {
log.Printf("received message from %s: %#x", name, msg.OpCode)
}
}
}()
}
} |
Hi @gobwas. Thank you for reply.
Nginx error.log I temporary solved issue by insert if condition to Receiver handler, but I don't sure that it right way if m.OpCode == ws.OpContinuation {
ch.state = false
break
} |
Wow. Looks like a bug currently. I will try to reproduce it tomorrow and investigate deeper in the problem (today I have no good Internet connection 😄). |
Thank you very much! I looking forward to you reply.... |
Hi @zebox! The bug has been reproduced and localized. I will think for a while to choose the way how to fix it. Will ping you when it will be fixed. Thanks! By the way,
|
Good! I will be wait for your fix. Thanks! |
This changes make necessary to call reader.NextFrame() before any interaction with reader.Read(). This will help to get rid of ambiguity of results from functions like ioutil.ReadAll() when nil bytes and nil (actually io.EOF -> nil) error returned. Fixes #39
This changes make necessary to call reader.NextFrame() before any interaction with reader.Read(). This will help to get rid of ambiguity of results from functions like ioutil.ReadAll() when nil bytes and nil (actually io.EOF -> nil) error returned. Fixes #39
I'm use your library for implement websocket (with Zero-copy upgrade). I have two object - Server and Client.
The Client has handler method Receive which listen data for each connection.
For connect to my WebSocket server i use Nginx as reverse-proxy and all works fine exclude one moment.
When on the nginx come proxy_read_timeout event I can't catch it in my code. After it event i get OpContinuation code and my Receive handler go to infinity loop (that load CPU to 100%).
I tried use ws.ParseCloseFrameData function, but payload data has lenght=0 and statusCode=0.
On the other side (web-browser client) gets event 1006 from nginx and browser disconnect properly.
Could you help me. What am I doing wrong?
The text was updated successfully, but these errors were encountered: