Skip to content
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

Disabling reconnection while reconnecting isn't working #5126

Closed
uncaught opened this issue Mar 10, 2024 · 2 comments
Closed

Disabling reconnection while reconnecting isn't working #5126

uncaught opened this issue Mar 10, 2024 · 2 comments
Labels
bug Something isn't working package:socket.io-client This concerns the "socket.io-client" package

Comments

@uncaught
Copy link

uncaught commented Mar 10, 2024

Describe the bug

I'm trying to disable reconnection while my site is in maintenance mode. But socket.io keeps trying to reconnect.

Basically I'm doing this (those are redux selectors, not important for the issue):

onSelectorChange(isInMaintenanceSelector, (inMaintenance) => {
  socket.io.reconnection(!inMaintenance);
  if (!inMaintenance) {
    socket.connect();
  }
});

But calling socket.io.reconnection(boolean) doesn't seem to have any effect.

To Reproduce

Socket.IO client version: 4.7.4

Client

import { io } from "socket.io-client";

window.socket = io("ws://localhost:3000/", {});

//Now stop your server and then after you see the reconnection attempts, try to disable the reconnections with:

window.socket.io.reconnection(false);

Expected behavior

socket.io.reconnection(false); should stop the reconnection loop until I activate it again, as described in the docs.

Platform:

  • Device: PC
  • OS: Windows 10
  • Browser: Chrome 122

Additional context

I've noticed earlier that socket.io.reconnectionDelay(number) also seems to have no effect on an ongoing reconnection, however this is harder to tell due to the random factor.

And yes, I could call disconnect explicitly, but the maintenance mode doesn't necessarily mean that the websocket server is gone. I just want to prevent reconnections if it is gone, too.

@uncaught uncaught added the to triage Waiting to be triaged by a member of the team label Mar 10, 2024
@darrachequesne
Copy link
Member

I could indeed reproduce the issue, thanks.

As a workaround, updating the skipReconnect attribute of the manager should work:

window.socket.io.skipReconnect = true;

And shouldn't interfere with subsequent reconnections.

@darrachequesne darrachequesne added bug Something isn't working and removed to triage Waiting to be triaged by a member of the team labels Mar 19, 2024
@darrachequesne darrachequesne transferred this issue from socketio/socket.io-client Jul 9, 2024
@darrachequesne darrachequesne added the package:socket.io-client This concerns the "socket.io-client" package label Jul 9, 2024
darrachequesne added a commit that referenced this issue Sep 18, 2024
```js
socket.io.on("reconnect_attempt", () => {
  socket.io.reconnection(false); // will now work properly
});
```

Related: #5126
@darrachequesne darrachequesne added this to the socket.io-client@next milestone Sep 18, 2024
@darrachequesne
Copy link
Member

For future readers:

This should be fixed by 13c6d2e, included in socket.io-client@4.8.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working package:socket.io-client This concerns the "socket.io-client" package
Projects
None yet
Development

No branches or pull requests

2 participants