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

Closing and reopening a connection which is reconnecting ends up with two connections #178

Open
mdmilic opened this issue Apr 18, 2024 · 0 comments

Comments

@mdmilic
Copy link

mdmilic commented Apr 18, 2024

Hi, I know it's been a while since this change has been introduced, but I was wondering if you could still remember the rationale behind it as it doesn't look right.

Scenario:

  • My websocket gets disconnected (e.g. by the remote) and start automatically reconnecting.
  • Due to various reasons I also have another reconnect mechanism in my app where I do socket.close() followed by socket.open().
  • When remote finally comes back, both mechanisms connect and I end up with two connections.

The reasons why both connect is because when socket.close() is called, the automatic reconnect mechanism doesn't stop (which doesn't seem right even in general case - I'm calling close explicitly so I want it to stop). This has been introduced since this PR quite a while back in particular the close() method change:

        // It seems to me that timer.shutdown() should be unconditional here
        if (options.reconnectInSeconds() <= 0 && !options.reconnect()  ) {
            timer.shutdown();
        }

Unfortunately I could not find a workaround for this issue so far. My close/open mechanism needs to kick in even if connection is in Open state (so I can't stop it if automatic reconnect succeeds first), but also when close/open mechanism succeeds first I can't stop automatic reconnect. Close also doesn't take any options that would make it stop reconnects.

I'd be happy to make the change, but since I don't understand the reasoning behind the condition I first want to understand if it can be removed or another approach is needed (e.g. add method to Socket to stop reconnects).

CC original author for visibility @ricardojlrufino

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant