question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reconnection after explicit disconnection

See original GitHub issue

Hi Currently, the lib tries to reconnect after explicit disconnection from the server with “io server disconnect”. According to the socket.io protocol, the lib should not start reconnection for “io server disconnect” and “io client disconnect” reasons. Even setting up Options.Reconnection to false in OnDisconnected event handler doesn`t help, because library starts reconnection before I have received and handled this event.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
jlareocommented, Jul 16, 2021

There are a lot of changes, I would wait a little bit until the tests are finished and we can guarantee that is stable enough

1reaction
doghappycommented, Jul 16, 2021

io server disconnect
io client disconnect

In the first two cases (explicit disconnection), the client will not try to reconnect and you need to manually call socket.connect().

I have fixed it. https://github.com/doghappy/socket.io-client-csharp/commit/08f458776a11c286ec645d29db9a2dbdb2c60c2f


But in any case we need to have a guarantee of events processing order: OnDisconnected => OnBeforeReconnect => OnReconnecting.

In this commit, I asserted the sequence of events.

When an event occurs, I add the event name to the array, and finally assert their order.


I modified the logic of connection and reconnection, so there is no need to add the OnDisconnectedInternal event.


I personally don’t like the idea of modifying the options object inside the Disconnected event.

me to 😃 , to do this, from a programming point of view, we only need to do this:

    public class ReconnectArgs
    {
        public ReconnectedArgs()
        {
            AutoReconnection = true;
        }

        public int Attempts { get; }
        public bool AutoReconnection { get; set; }
    }

...

// public event EventHandler<int> OnReconnectAttempt;
public event EventHandler<ReconnectArgs> OnReconnectAttempt;

...
var args = new ReconnectArgs();
args.Attempts = Attempts;
//OnReconnectAttempt?.Invoke(this, Attempts);
OnReconnectAttempt?.Invoke(this, args);
if (!args.AutoReconnection)
    // to do

...

// subscriber
        private void SocketIO_OnReconnectAttempt(object sender, ReconnectArgs e)
        {
            if (condition)
            {
                e.AutoReconnection = false;
            }
        }

help subscribers to tune own business logic correctly and cancel reconnection flow if it’s required

In this scenario, can the problem be solved by calling “Dispose()”?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Automatic reconnect stopped after explicit connection attempt
Calling connect while the client is reconnecting stops any further reconnection attempts, even after connecting and disconnecting again.
Read more >
How can you re-use or reconnect to a socket on the same ...
My question, to restate, is to be able to use the same socket (more importantly the same port) to reconnect after the client...
Read more >
OpenVPN is not working if client is reconnected immediately
My problem is the following: If I disconnect and reconnect openvpn client immediately, the connection succeeds, but I cannot access services ...
Read more >
SERVICE DISCONNECTION/RECONNECTION
According to the customizing settings, you might need to close the disconnection document explicitly after the reconnection. This is to indicate ...
Read more >
The Socket instance (client-side)
In the first two cases (explicit disconnection), the client will not try to reconnect and you need to manually call socket.connect() .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found