-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
ws methods called on a ws that is already closed close current connection silently #12
Comments
If there is a LBYL approach to this, that would also work. |
This is working as designed, it's just that you are doing something that is unusual. Let me try to explain. The expected use is that within a WebSocket route you will use the The unusual thing that you are doing is that you are using the |
Thanks, I was confused by what was going on behind the scenes. It turns out I might have figured this out by using try:
data = clients[0].receive()
clients[0].send(data)
except Exception as e:
print(e.__class__, flush=True) It looks like the built-in catching is done here.
Might I ask how you would implement this idea? Should I bring in a messaging queue piece for different ws to talk to each other?
So the resources are already freed when connection A closes, thus I do not need to worry about freeing them when connection B throws this exception for connection A? |
I guess maybe this is where I switch to flask-socketio? |
Just catch
That's correct, in your case receiving a
Not sure. Maybe? The event model in Flask-SocketIO may make your usage less confusing/unusual, but I think you can do what you want with this extension, as long as you handle those |
Thank you again. "less confusing/unusual" is probably a good thing. I will investigate whether the flask-socketio event model has what I am looking for, so as to avoid reinventing the wheel if possible. Otherwise, it is good to know that I am in the clear with this. The use case is definitely atypical. I am using ws to drive the browser of an embedded device from another client. |
To clarify for future reference, my use case needs 'get client by ID' functionality which requires a mapping of ID to client. This is certainly possible to implement with flask-sock. You have the connect event. Use this to do flask-socketio already has this implemented via The workflow for handling the disconnect event is a good candidate for the docs, either in the example or the API. |
I am trying to keep track of connected clients and send messages to them. I connect with one client, store its websocket in memory, and then disconnect. I then connect with another client and try to interact with the websocket of the previous client that is no longer open.
When
receive
orsend
are called on a websocket that is already closed, the current connection closes with1000 Normal Closure
. What I would expect is an exception to be thrown so that I can catch it, remove the dead websocket object, and continue on with the current websocket.I have included code to reproduce this issue and example output.
app.py
Client
STDOUT
The text was updated successfully, but these errors were encountered: