Closed imrankhan17 closed 3 years ago
Hmm. I don't really get any errors on the server when the connection is closed. What OS are you using? I'm testing on Mac.
Ubuntu 20.04.2 LTS. I should add that the server continues to accept new connections and send data without needing to restart, but the same error appears every time.
I just tried it on Mac and I get the same error.
Version of Python? There's got to be a difference, I don't see any errors here. I'm on 3.8.6.
Same here.
Python 3.8.6 (default, Nov 20 2020, 18:02:11)
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
@imrankhan17 I basically coded a fix for your error without actually being able to reproduce it here. Please upgrade flask-sock and simple-websocket and let me know if that works better for you.
I installed the latest commit for flask-sock and upgraded simple-websocket and it works fine for me now - thanks a lot for that fix. Interestingly, it also worked if I only upgraded simple-websocket to 0.2.0 but kept flask-sock at the 0.3.0 release.
@imrankhan17 yeah, that's expected. I added a handler for the LocalProtocolError
you were getting in simple-websocket. The change I've made in this package is intended to attempt to close the websocket connection after the application's handler returns.
I've been using this package for some time and it works very well. I'm still trying to determine the best way to close a websocket connection using
ws.close()
. After a connection is made by a client and the data has finished being sent, I get this error on the server side (full stack trace below):Here is the code to reproduce this error. I'm running Python 3.8.5 on Ubuntu.
In a file called
app.py
:I use
flask run
to start the application. In another tab, I'm using wscat to connect to the websocket on localhost:This works fine, however on the server side I get the aforementioned error:
Alternatively, if I remove the
ws.close()
line, I don't get an error on the server, instead I see this on the client: