-
-
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 does not register disconnected Safari browser #2025
Comments
Sorry, I have no MacOSX box -- Linux only. |
Btw, Firefox behaves the same way as Chrome: Both aiohttp and websockets register the disconnect. So yes, this will need someone with macOS. |
I'll check this |
@Azag0 I think it's related with #2368 and #2309. Looks like Firefox and Chrome send a special CLOSE frame just before the tab will be reloaded and the connection will be closed. So, in a case of those two browsers, connection is closed gracefully, by a server, in response to the CLOSE frame. Safari, on the other side, just closes connection abruptly, without sending a CLOSE frame. And thus for some reason aiohttp keeps listening for new packets, even if the client is gone and underlying connection was closed. Again, it's all just assumptions. I'm a Linux user too and can't test behavior of Safari. But you can test it yourself - just enable asyncio debugging mode and watch for the following message: UPD: But there is a workaround: #2283 (comment) UPD2: Also attempts to receive the next frame on a closed connection raise CancelledErrors: #2061. So we can just catch CancelledError exceptions to detect disconnections. UPD3: Possibly, heartbeats (periodic pings) are also mandatory for disconnection detection to work |
See #2675 for cancellation logic changing. I'm closing the issue because of long inactivity period, I even not sure that the problem exists. |
I have slightly updated the code snippet to work with the current @s-kostyuk I get no messages about client disconnection when the asyncio debug mode is enabled. This is really a non-issue, I guess. If the aiohttp websocket server just responds to requests from the client, it will never know that the client had died, but that doesn't really matter. If it sends messages to the client without any prompt, it will find out from the thrown exception. |
@Azag0, so, the only thing I can recommend is to enable heatbeat, handle exceptions and implement some acknowledge mechanisms if it's important to ensure that a message was delivered to client. Otherwise, if client lost connection to the server (WiFi gone down, for example), the server will not notice half-closed connection and will send messages as usual... to nowhere |
Problem still exist with 3.3.2 :( |
@s-kostyuk Also try heartbeat and timeout and auto close but it's not working |
@james4388 I'm starting to thing that the whole situation with disconnection detection will stay mysterious until someone will get a Wireshark, a descent debugger and will finally debug/fix WebSocket implementation. And considering to try Sanic for future projects, because Sanic uses aaugustin/websockets as WS implementation |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs. |
With Websockets, when Safari is reloaded or tab closed, the websocket server registers a closed connection. This is not the case with Aiohttp. But Aiohttp correctly registers the disconnection with Chrome. I don't know anything about the websocket protocol internals, but I guess there is a difference in what both browsers send on tab close/reload. In any case, Websockets somehow registers that event in both browsers, but Aiohttp doesn't.
Take the following app. When going to http://localhost:8080/websockets and reloading the site several times, the app emits alternating "Got client", "Lost client" with both Safari and Chrome. Now go to http://localhost:8080/aiohttp: only Chrome triggers lost connections.
The text was updated successfully, but these errors were encountered: