reconnecting users on websocket connections using -'python,architecture,websocket,server,tornado'

reconnecting users on websocket connections  using -'python,architecture,websocket,server,tornado'

We have a platform (app + web app) where users connect to the server through a WebSocket connection.

For architecture design and security reasons, we want to limit each user to use no more than 1 concurrent connection.

We use python's tornado as a websocket handler and maintain a global list of connected users.

that's how our open() function looks like:

def open():
    """connections {user_id: ws_handler}
    global connections
    user_id = self.get_argument("user_id", None)
    if user_id and user_id not in connections.keys():
         connections[user_id] = self
         # proceed
         # replace the old connection
         connections[user_id] = self

Initially, we would reject the second incoming connection for a given user. A problem with mobile devices losing network connection made us change our solution - in such case no .close() is initiated for the WebSocket connection. So, we decided to replace the old connection with a new one.

The problem we are facing currently is with clients on multiple browser windows - clients try to reconnect and to tabs/windows go into sort of a reconnect battle. One connects and disconnects the other, the other reconnects and disconnects the first one. We have automatic reconnect implemented in our clients (both app and web) so that they automatically reconnect when (for whatever reason, usually network conditions) connection is dropped.

We tried playing with exponential back-off but that does not seem to be a satisfactory solution.


Are there any people who dealt with a similar problem?

Is there a common design pattern to tackle this problem?

asked Sep 7, 2015 by rajesh
0 votes

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.