Network disconnect / offline mode not detected
See original GitHub issueDescribe the bug When turning off the wireless network on my MacBook, the client does not detect the disconnect event. It waits a possibly long time until the ping detects it. Using Websockets.
To Reproduce Any basic example will replicate it, for example https://socket.io/demos/chat/ replicates it.
Server Does not matter, it is disconnected on the client.
Socket.IO client version: 3.0.4
Client
Default options, only auth
is specified in options.
Expected behavior A clear and concise description of what you expected to happen.
When disconnecting the network, the socket should detect a disconnect event. The browser correctly recognizes such event, the following triggers immediately.
window.addEventListener('offline', () => {alert('offline')});
navigator.onLine
is also correctly showing false.
However SocketIO client believes it is still connected, the WS connection is sending messages like everything was connected. Only after the next ping event it recognizes that something is wrong and fires the disconnect event.
Platform:
- Device: Macbook Pro
- OS: macOS 10.15.7
- Browser: latest Chrome and Firefox
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top GitHub Comments
@dverzolla I don’t think this is fixed yet.
@hyperknot I could indeed reproduce, thanks. That’s really weird, one could expect that the TCP connection would be closed when the network is turned off, but that does not seem to be the case.
This should be fixed by https://github.com/socketio/engine.io-client/commit/c361bc691f510b96f8909c5e6c62a4635d50275c, included in
socket.io-client@4.0.0
.Thanks for the detailed bug report 👍