-
-
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 stream does not close when connection is abruptly cut #961
Comments
I also see this. |
Same problem as #827 |
There are two solutions for the problem:
Maybe we need both solutions |
Seems to be working in Google Chrome (52.0.2743.116 m). Ping/Ping HeartbeatI tried implementing Insoleet's solution using ping/pong as a heartbeat. It works somewhat. The heartbeat correctly detects that the connection is closed. However, even though Here is the logs that I've gathered from the event. First, the confirmation that the heartbeat mechanism is closing the
Then (14 mins later), an exception is logged. Seemingly, this exception originates from somewhere within asyncio itself.
Lastly, I get the following exception message from the
Seemingly, some asyncio internals are acting up when the connection is abruptly cut which can't be handled in user code. Python 3.5.1 and Aiohttp 0.22.5. |
14 mins delay surprises me a lot. |
Despite the heartbeat mechanism, I have some users of my application who complained that the websockets would freeze if they were in a bad wifi area network. I suppose that it is because @frederikaalund : could you check if you reopen your connection before the exceptions are thrown if the ws ever close ? Also, the problem with closing the websockets could be linked to the other problem I found : #754 Right now I'm forced to cancel websockets coroutines to close them when I stop my application. |
Me too! I just repeated the test. Same result:
Approximately 15 mins delay this time.
It would be great to see a fix. Any approximative 1.0 release date? Like, is it one or two years from now?
Do you mean to call |
No, I was thinking about the following test :
|
I hope to publish it in a few days actually. Just after fixing problems with client cookie jar.
|
Sounds great!
I tried but it wouldn't reconnect. The client (Google Chrome) treats the connection as closed. In any case, no more data is sent from the server after
That's the strangest part. |
That's how TCP works. If you send something, TCP sends the data and expects ack, and retries send if ack not received. And after TCP timeout (usually 2 minutes), the connection will be closed. But if you are reading from a socket and there is no incoming data, there is nothing wrong, you should wait forever, or have a timeout at a higher level (like keep-alive timeout). |
That may explain the error.
That's what I think aiohttp should have built-in. |
|
All send methods return drain corouting + heartbeat system, should be sufficient |
@fafhrd91 So has a hearbeat been built into AioHTTP? Excuse me for being a bit out of the loop. |
@frederikaalund yes, it is parameter for |
Long story short
Websocket stream does not close when connection is abruptly cut (e.g., pulling the network cable). This causes the connection to erroneously buffer the writes until the process runs out of memory.
Expected behaviour
When a connection is abruptly cut, I expect that either:
WebSocketResponse
'ssend_bytes
andsend_string
methods raise an exception.async for msg in ws: pass
loop returns.Actual behaviour
The websocket stream is kept alive forever, never recognizing the connection failure.
Steps to reproduce
The following server program reproduces the error:
Pair it with the following HTML client:
Now, if you simply connect, you will start to see the messages in the console. The memory usage of the Python process is constant as expected. Refreshing the browser window (closing and reopening the connection) also works (the connection is logged as closed and opened on the server).
However, if you abruptly cut the connection (e.g., by removing the network cable or disabling the network interface) then the server does not register that the connection is closed. Not even within a reasonable timeout period (I had a process running for 15 mins). Instead, the writes are seemingly buffered until the Python process runs out of memory.
Your environment
Asyncio 0.21.6. Python 3.5.1
The text was updated successfully, but these errors were encountered: