Skip to content

Managing Stale Websocket Connections #821

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

Closed
kmiklas opened this issue Aug 28, 2020 · 1 comment
Closed

Managing Stale Websocket Connections #821

kmiklas opened this issue Aug 28, 2020 · 1 comment

Comments

@kmiklas
Copy link

kmiklas commented Aug 28, 2020

Note: Also documented on SO here:
https://stackoverflow.com/questions/63639414/how-to-manage-stale-websocket-connections]

Using Python Websockets [1] to manage a set of server-side websocket connections from browser. They must be registered and maintained.

Problem: when User disconnects a stale connection remains present in the registry. Also, if user refreshes browser (1, 2, 17... or n times), or a reconnect script is present, more invalid connections are registered. This creates a big registry of stale connections.

The docs address this issue as follows:

As shown in the synchronization example above, if you need to maintain
a list of currently connected clients, you must register them when
they connect and unregister them when they disconnect.

How are stale connections properly identified and removed? Is some sort of ping/pong scheme required?

I did find the code in [2], but it goes back to 2018. Is this obsolete, or has this issue since been addressed?

Ref:

  1. https://websockets.readthedocs.io/en/stable/intro.html
  2. Common pattern for reconnections #414
@aaugustin
Copy link
Member

The example here (https://websockets.readthedocs.io/en/stable/intro.html#registration) removes stale connections:

    finally:
        # Unregister.
        connected.remove(websocket)    

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