Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tornado WebSocket closes once a minute

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?

like image 275
user1387717 Avatar asked May 02 '13 16:05

user1387717


People also ask

What causes WebSocket to close?

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.

How long can WebSocket stay open?

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.

Does WebSocket have timeout?

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.


1 Answers

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.

like image 151
Ross117 Avatar answered Oct 04 '22 00:10

Ross117