socketio / socket.io

Realtime application framework (Node.JS server)
https://socket.io
MIT License
60.92k stars 10.09k forks source link

Network change results in incorrect connection status on the client. #4843

Open akilude opened 11 months ago

akilude commented 11 months ago

Describe the bug This happens when a user changes the network on the fly. When switching networks, the socket.io client goes from connected to disconnected to reconnected state. But the actual socket does not send or receive data for a lot longer (normally 30-45 seconds)

Additional info: The socket.io server is behind nginx.

To Reproduce

  1. Client side, connect to the socket.io server
  2. Switch networks (If you have multiple Wifi networks, you can switch to another network, on phone you can switch between wifi and cellular network)
  3. Sometimes the socket.io client emits the disconnected event
  4. After the network is changed, normally in less than 5 seconds the reconnect event is emitted
  5. The socket is not actually connected, messages cannot be sent/received from the server, messages are instead queued, normally after 30-45 seconds post the reconnect event, messages start flowing as usual.

Please fill the following code example:

Socket.IO server version: 4.7.2 Socket.IO client version: 4.7.2

Expected behavior The client socket must be actually connected when it emits the reconnect event.

On a slightly off topic note, v4 of socket.io has been a joy to develop with. Thank you to all socket.io maintainers.

darrachequesne commented 11 months ago

On a slightly off topic note, v4 of socket.io has been a joy to develop with. Thank you to all socket.io maintainers.

Thanks a lot for the kind words :heart:

Regarding your issue, I was not able to reproduce when switching from wifi to 4G (Chrome 117, Android):

https://github.com/socketio/socket.io/assets/13031701/c1cb342c-bddc-4e5a-9a44-22077c416062

The client reconnects right away and receives "pong" events from the server.

Does it happen on all platforms?

akilude commented 11 months ago

I will create a minimal example and share here.

Have tested on Android chrome 117, and Mac chrome 117.

One small change is that i have only one network interface open at a time. So the device has wifi on, cellular data off, then i switch off wifi and turn on cellular data