socket.iogevent-socketio

Socket.IO : What is the recommended pattern for server side cleanup?


Is it enough to cleanup on disconnect? What happens if a browser disappears before sending an explicit disconnect?

What is the recommended pattern for server side cleanup, so that the resources bound to the connection are not leaked (e.g. Namespace)?

(using gevent-socketio, if it matters)


Solution

  • If you use WebSockets as transport, it would automaticaly disconnect the socket on browser close. If you use xhr-polling for example it would not automaticaly disconnect (speaking about gevent-socketio).

    My approach when xhr-polling is used was:

    1. Saving the socket session id among with logged in user id in database
    2. On next user login detect if such a record exists
    3. Use the stored session id in the record to disconect the unused socket since the fresh user login would generate new socket

    This is not rapid solution since you may have unused sockets connected until new login is performed by the user, but it performs a kind of cleanup when the user log in.

    This article may be a hint to something more creative than mine solution: http://flask.pocoo.org/snippets/71/