Skip to content
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

on_close handler doesn't seem to be called upon interruption to websocket connection #1210

Closed
aaronjwood opened this issue Sep 26, 2014 · 1 comment

Comments

@aaronjwood
Copy link

I have an application that keeps track of connected clients and "locks" editable fields for other clients until there are no other clients trying to access it. The page is "locked" when someone loads the page and establishes a connection with the tornado socket server. Once that user moves to another page or closes the browser/tab the socket server removes them from the dictionary of connected clients so that another client that's waiting can start their workflow.

Testing this functionality over the VPN from home one day led me to find that if I disconnect from the VPN and then close the page or navigate away from the page that establishes a socket connection tornado doesn't seem to call the on_close method. This causes the client to be stored in the dictionary until the socket server is restarted.

Shouldn't tornado be calling on_close upon a disconnect OR an interruption to the connection?

I'm using tornado 4.0.1 with python 3.4.

@bdarnell
Copy link
Member

Idle connections can be kept open indefinitely without any data passing back and forth, so it's impossible to distinguish a connection that is deliberately left idle from one that has been broken by the loss of some intermediate network path. The only guaranteed way to detect that a connection has failed is to try to send data on it and get a response from the other side. You should send some sort of heartbeat back and forth (perhaps using the WebSocketHandler.ping method), and close the connection if it's been too long since the last heartbeat response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants