-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Websocket reading message loop raises low-level CanceledError when connection is closed unexpectedly #2061
Comments
Technically aiohttp creates a task per client request.
The only thing I could suggest is catching
Or you could just don't catch so broad type like |
I see two options:
|
Maybe it's better to introduce a separate ConnectionClosed exception, in the same way as was done in websockets library? |
I think I have just been bitten by this behavior. I had some code like this:
After putting it in production I found that the exiting part of
This is a really weird problem, particularly because how it breaks the expectation that the exiting part of a context manager will always run. I had to basically shield all the async contexts from cancellation, like this:
Is there a better way to do this? |
Actual behaviour
Reading message loop
async for msg in ws:
raises low-levelconcurrent.futures._base.CancelledError
when connection is closed unexpectedly.Expected behaviour
Expected to get message with type
aiohtto.http_websocket.WSMsgType.ERROR
, or silently stop the loop, or at leastaiohtto.http_websocket.WebSocketError
.Steps to reproduce
Run the following two scripts
server.py
andclient.py
, then stopclient.py
byCtrl+C
.server.py
client.py
Log output of
server.py
Your environment
OS: CentOS Linux 7
Linux kernel: 3.10.0-514.16.1.el7.x86_64
Python: 3.5.3
aiohttp: 2.2.3
The text was updated successfully, but these errors were encountered: