Comments (6)
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 io.EOF
error.
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)
}
}
}()
}
}
from ws.
Hi @gobwas. Thank you for reply.
I tested nginx as reverse proxy with your code. I set proxy_read_timeout=30s.
Nginx address is 192.168.56.102:9999 ----reverse-to-ws--> 192.168.56.1:8080
Debug console output bellow:
2018/04/14 15:33:17 accept from 192.168.56.102:51642
2018/04/14 15:33:17 upgrade 192.168.56.102:51642 ok
2018/04/14 15:33:47 received message from 192.168.56.102:51636: 0x0
2018/04/14 15:33:47 received message from 192.168.56.102:51636: 0x0
2018/04/14 15:33:47 received message from 192.168.56.102:51636: 0x0
2018/04/14 15:33:47 received message from 192.168.56.102:51636: 0x0
2018/04/14 15:33:47 received message from 192.168.56.102:51636: 0x0
2018/04/14 15:33:47 received message from 192.168.56.102:51636: 0x0
2018/04/14 15:33:47 received message from 192.168.56.102:51636: 0x0
2018/04/14 15:33:47 received message from 192.168.56.102:51636: 0x0
2018/04/14 15:33:47 received message from 192.168.56.102:51636: 0x0
2018/04/14 15:33:47 received message from 192.168.56.102:51636: 0x0
....
....infinity loop
....
2018/04/14 15:33:47 received message from 192.168.56.102:51636: 0x0
2018/04/14 15:33:47 received message from 192.168.56.102:51636: 0x0
2018/04/14 15:33:47 received message from 192.168.56.102:51636: 0x0
2018/04/14 15:33:47 received message from 192.168.56.102:51636: 0x0
2018/04/14 15:33:47 received message from 192.168.56.102:51636: 0x0
2018/04/14 15:33:47 received message from 192.168.56.102:51636: 0x0
...
...
...
Nginx error.log
2018/04/14 15:36:32 [error] 1621#1621: *5 recv() failed (104: Connection reset by peer) while proxying upgraded connection, client: 192.168.56.1, server: 192.168.56.102, request: "GET /ws HTTP/1.1", upstream: "http://192.168.56.1:8080/ws", host: "192.168.56.102:9999"
This error occur after websocket service stops (for interrupt infinite loop).
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
}
from ws.
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 😄).
from ws.
Thank you very much! I looking forward to you reply....
Also I tried using gorilla/websocket lib and it got 1006 code from nginx when timeout disconnect .
from ws.
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, gorilla/websocket
returns 1006
code accordingly to the RFC6455:
1006 is a reserved value and MUST NOT be set as a status code in a
Close control frame by an endpoint. It is designated for use in
applications expecting a status code to indicate that the
connection was closed abnormally, e.g., without sending or
receiving a Close control frame.
from ws.
Good! I will be wait for your fix. Thanks!
from ws.
Related Issues (20)
- Question: client example
- EOF error on ws.Upgrade HOT 8
- Is it necessary to use sync.Pool to reuse Reader Object in readData? HOT 1
- Read and Write timeouts? HOT 5
- Handshake.Extentions pointing to a buffer already returned to pbufio.ReaderPool
- State of the package and security updates HOT 6
- Websocket error on Safari HOT 4
- Dialer's Header parameter doesn't work as intended HOT 6
- Is WriteServerMessage thread-safe? HOT 9
- json decoder or unmarshaler? HOT 2
- Client-side example? HOT 5
- readme example problem HOT 1
- Correct way to handle continuation frame? HOT 1
- ReadFrame maxs out at 4096 lengths HOT 11
- RSV1 set, FIN not set on control using wsutil HOT 1
- Question - add headers during the upgrade HOT 2
- message rate limiter HOT 1
- Client disconnects on its own due to the 1008 error and EOF error. HOT 8
- Any example for using this library with `gnet`? HOT 5
- I encountered a problem of automatic disconnection after 30 seconds HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ws.