gevent-socketio
gevent-socketio copied to clipboard
Disconnect not firing
For some reason the disconnect isn't firing. Here is the simple app I created that I am having issue with. I am using the 0.9.10 client.
https://gist.github.com/a53d1acc83b06b16d263
Also posted question on SO. http://stackoverflow.com/questions/12411215/python-gevent-socketio-memory-leak-disconnect-not-firing
recv_disconnect is firing by the user, not the server. Either you have to make the user disconnect (adding a link or button?) or use events like "beforeunload" or "unload" to call it. In both situations you will need to call socket.disconnect().
Example:
$(window).on('beforeunload',function(){socket.disconnect();});
Hope this helped you a bit.
Best regards,
Andreas
Yeah.. the pattern is not extraordinary, but recv_disconnect() was meant for catching the DISCONNECT packet.. while disconnect() is called when gevent-socketio detects the client was disconnected. This is not well documented though.. but you can override disconnect() itself in your Namespace, and call the parent disconnect() function (with super(...)). It's not that elegant, it's true...
Anyone has suggestions on how we could make this better ?
I didn't want to have an on_disconnect(), because its confusing with the events (and its a different packet type, not an EVENT per se), and recv_* were meant for those other packet types.. but then when the client disconnects, disconnect() was the only thing I could think of.. but then again, we need to have stuff happening in this method (like killing all spawn'd greenlets).
So disconnect() is called internally, when the client actually disconnected (timed out, or websocket connection closed), I think with "silent=True", so that no DISCONNECT packet is sent.. but you can all it also, or override it in your Namespace.
Let's find a good solution together if you please :)
Alexandre
On Mon, Sep 17, 2012 at 6:58 AM, Andreas Porevopoulos < [email protected]> wrote:
recv_disconnect is firing by the user, not the server. Either you have to make the user disconnect (adding a link or button?) or use events like "beforeunload" or "unload" to call it. In both situations you will need to call socket.disconnect().
Example:
$(window).on('beforeunload',function(){socket.disconnect();});
Hope this helped you a bit.
Best regards,
Andreas
— Reply to this email directly or view it on GitHubhttps://github.com/abourget/gevent-socketio/issues/88#issuecomment-8610788.
@sv1jsb Thanks, this makes sense. @abourget I see. The best thing my little brain can think of is disconnected() The past tense of disconnect (disconnected) would imply that it's called at the end of disconnect for user defined ops.