socket.io-client icon indicating copy to clipboard operation
socket.io-client copied to clipboard

When client restore connection, will have multiple connections

Open jackniu81 opened this issue 6 years ago • 5 comments

You want to:

  • [x] report a bug
  • [ ] request a feature

Current behaviour

I'm testing on Samsung J7, Android 8.0, cordova -WebView. socket.io version: 1.7.2.

After socket.io connection lost, and then wifi restore, socket.io will restore too. But sometimes, it will result to several connection, and i expect to only 1 connection. Sometimes, there are 10 restored connections. Although only 1 connection will be kept at last, but this is not expected.

Steps to reproduce (if the current behaviour is a bug)

Testing on Samsung J7, Android 8.0, cordova -WebView. socket.io version: 1.7.2.

  1. Start the client on webview
  2. stop wifi, to stop the socket.io connection
  3. Restore wifi 1 minutes later
  4. check connections from the server after client connection restored

Actual Result: there will be multiple connections from server side. And will only keep 1 connections about 1 minute later

Expected behaviour

Only see 1 connection from server side

Setup

  • OS: Windows
  • browser: Chrome
  • socket.io version: 1.7.2

Other information (e.g. stacktraces, related issues, suggestions how to fix)

jackniu81 avatar Feb 19 '19 00:02 jackniu81

I am having a similar issue, that my emitted messages during connection lost get send randomly. Did you figure out something?

ghost avatar Mar 03 '19 21:03 ghost

Feels like a typical HTTP/1.1 problem, that when a connection is lost and then restored, there isn't a great way to know if it's a new device connecting to the server, or an existing one that restores the connection. I suspect that your IP changed during the wifi reboot, some ISP do that and would change how server see clients.

Chopinsky avatar Mar 06 '19 05:03 Chopinsky

@Chopinsky , thanks for your replay. But i'm sure, the IP not changed, I do have logs in the server side, even the session-id(I use session for socket.io authentication) is not changed.

jackniu81 avatar Mar 07 '19 00:03 jackniu81

Has anyone resolved the problem?It occured to me for several times.I have no idea till now.

lst94 avatar Apr 09 '19 06:04 lst94

Has anyone resolved the problem? same here

ezequielvictor avatar May 22 '20 14:05 ezequielvictor

For future readers:

This is expected, because the server may not be aware of the client disconnection right away. It will eventually be aware of the disconnection once the heartbeat for the previous connection fails, which may take up to 45 seconds (pingInterval (25s) + pingTimeout (20s)).

Reference: https://socket.io/docs/v4/server-options/#pinginterval

darrachequesne avatar Apr 10 '24 13:04 darrachequesne