I'm using Closure client-side and Tornado server side. I create a socket:
this.socket = goog.net.WebSocket(true)
and then open it:
this.socket.open(theSocketUrl)
Every works fine including messages being passed correctly. However, once per minute (once every 60 to 61 seconds), the socket closes and then reopens. There are no errors server-side and the Closure socket error event doesn't get called.
I've added logging to tornado and something seems to be calling on_connection_close() which then calls the socket's method on_close(). The close() method itself does not get called.
Any idea why this might be happening?
The main reason is that the connection was closed abnormally (locally) by the browser implementation. It means that your browser cannot reach your remote code server. The main issue is about your https connection to the server.
A WebSocket connection can in theory last forever. Assuming the endpoints remain up, one common reason why long-lived TCP connections eventually terminate is inactivity.
The websocket-idle-timeout command sets the maximum idle time for client connections with the handler. This timer monitors the idle time in the data transfer process. If the specified idle time is exceeded, the connection is torn down.
Are you using nginx or some other reverse-proxy in front of your tornado server? I've seen this happen when the proxy timeout elapses and then nginx closes the connection, causing the behavior you're seeing.
You can change the proxy_send_timeout
and proxy_read_timeout
in nginx to prevent this. Just make sure that when you edit proxy.conf
, you include it from your main nginx.conf
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With