Atmosphere / wasync

WebSockets with fallback transports client library for Node.js, Android and Java
http://async-io.org
161 stars 47 forks source link

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

Open mdmilic opened 5 months ago

mdmilic commented 5 months ago

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:

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