-
-
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
async for message in ws exits for unknown reasons? #6707
Comments
The code is very simple and clear: Line 321 in 65bf205
It exits because the server tells it the connection is being closed. This is the expected behaviour, not an error state that should raise an exception. |
Thank you for pointing me to the relevant code @Dreamsorcerer. From what I can see the Or does the |
Meanwhile I found the |
Yes, raising an exception is the end of a function call, no value will be returned.
Looking at that same code, it appears that Line 282 in 65bf205
|
Hmmm. Thank you for pointing that out. Looking deeper I see that:
Peculiar. Well. Please @Dreamsorcerer, have a look at the Question #6710, would that be a good approach? |
Unless |
As far as I can see this in an internal message indicating that the connection is already closed, not a message from the server.
Again, this appears to be an internal message from calling .close(), not from the server.
The code for .json() is just So, maybe we should save this as an attribute in addition to close_code. As a temporary workaround (and to check it contains the information you're looking for), try writing the loop manually with something like:
|
So, sounds like the connection is actually closed by the client? How do I find out why? I only see the loop exited. |
Based on what? What was the last msg you see? |
Describe the bug
The "async for message in ws" loop ends inexplicably.
To Reproduce
I'm using this code to connect with a wss:// address and process the messages it returns:
If self._config['streams] contains a list of streams known to the server, everything works flawlessly.
The problem arises when I intentionally try to subscribe to a stream that the server doesn't know about. In this case I receive the following message from the server:
The message itself is what I expect and doesn't seem to be special in any way. Mysteriously however, the flow of the program exits the loop and the connection is closed.
(This happens irrespective of autoclose being set to True or False, but I don't know if this is relevant)
Expected behavior
If the server closed the connection, i.e. because its logic accepts absolutely zero errors from me, I would expect aiohttp to tell me the closure was caused by the server or see one last message from the server warning me about the closure.
And there have been other instances of the loop exiting and the connection closing seemingly without reasons, at random times over multi-hours runs when everything seems to work. Attempting to subscribe to a stream that doesn't exist is just a way to trigger the issue reliably.
If something happened client side, I would also expect aiohttp to tell me, i.e. via an exception, but I get absolutely nothing. The loop just ends and the connection is closed.
Basically I'm left wondering: is the loop exiting ONLY if the websocket connection is closed? If it is, how do I know if it's the client or the server that triggered the closure? If it isn't what are the other causes?
Logs/tracebacks
Python Version
aiohttp Version
multidict Version
yarl Version
OS
Windows 10
Related component
Client
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: