-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Disconnect after 5 minutes if tab minimized on Chromium #4040
Comments
Thanks for the detailed issue and the link 👍 The problem with increasing the default value of (currently the timer is set to 45 seconds, as That being said, if the browser decides to close the connection to save the battery, I'm not sure we should intervene. What do you think? |
If I read it correctly the websocket connection should stay open, even if battery saving is active. It's just the ping timeout which closes the websocket connection. I'd say that this is a minor problem on socket.io's side. |
I tried to reproduce the same behavior with plain Web Sockets and the connection is still kept open even if the tab is throttled, so I think that as @GingerAdonis says is just a matter of the ping timeout. I'm not completely sure if something has to be changed in the library, maybe adding just a note in the Disconnection detection section of the documentation may be enough for other users thay may experience this problem, and then each one can adjust the ping timeout depending on the application. |
I managed to solve a problem that did not exist on socket.io 2.x, it was to set this parameter https://socket.io/docs/v4/client-initialization/#closeOnBeforeunload to false Here is how to reproduce the problem (this was done in production mode and not on a test version):
Now I have a second problem that I still can't solve, but which works fine on socket.io 2.x: as a new user, occasionally it refuses to connect to the socket, there is no error however. You just have to refresh the page and then it's good to start. |
For future readers: this should be fixed by socketio/engine.io-client@f30a10b, included in I've added a note in the troubleshooting guide: https://socket.io/docs/v4/troubleshooting-connection-issues/#the-browser-tab-was-minimized-and-heartbeat-has-failed |
Describe the bug
Using a Chromium browser, when the tab through which the connection is established is minimized for more than 5 minutes, the client gets disconnected by the server due to a
ping timeout
.To Reproduce
Socket.IO server version:
4.1.3
Server
Socket.IO client version:
4.0.1
Client
Server log:
Expected behavior
The server should keep receiving messages after 5 minutes even if the tab is minimized. Since browsers do some battery optimization, it is possible that the messages don't arrive at the correct interval, but the connection should still be kept open.
Platform:
Additional context
In this case the problem is that the server default
pingTimeout
is not high enough to be able to correctly receive a pong response from the client if it has been minimized for more than 5 minutes, probably due to Chrome Intensive Throttling.If I try to increase the
pingTimeout
interval from the server, I am able to keep the connection opened. By doing some experiments I found out that I can set it as low as 44 seconds for the client to be able to reply to the ping message.Even if this is an expected behavior, shouldn't the default interval be higher? In any case the problem can be solved by setting it to 60000.
The text was updated successfully, but these errors were encountered: