Take the following console app
static void Main(string[] args)
{
Thread connector = new Thread(Connector);
connector.Start();
while (true)
{
Thread.Sleep(500);
}
}
private static void Connector()
{
SignalR.Client.Hubs.HubConnection connection = new SignalR.Client.Hubs.HubConnection("http://192.168.42.10:1327/Chat");
SignalR.Client.Hubs.IHubProxy loginHub = connection.CreateProxy("LoginHub");
connection.Received += connection_Received;
connection.Reconnected += connection_Reconnected;
connection.StateChanged += connection_StateChanged;
connection.Error += connection_Error;
connection.Closed += connection_Closed;
connection.Start().Wait();
}
LoginHub implements IDisconnect.
If I start the app, let it connect, pull the network cable, wait for the server side disconnect event to fire, reconnect network cable, the client will reconnect and then immediately have its connection closed.
If I unplug and replug the network cable before the server side disconnect fires, the connection reconnects just fine.
Is this intended behaviour? How is reconnect supposed to work?
EDITED (re-read and saw that I wasn’t being clear): When the client is immediately disconnected with SSE, in most cases (in 0.5.3) it will be thrown into an infinite reconnecting loop (see bug below).
However, in some cases it will reconnect and then immediately disconnect, which is intentional behavior. The reason why we force the client to disconnect is because at this point the server has completely forgotten about the client. Therefore the client needs to re-instantiate it’s connection via the $.connection.hub.start etc.
In the next release, we have fixed the infinite reconnect issues and have also added a “warning” to the process to notify developers that the server may be down (onConnectionSlow). Granted if you successfully reconnect and the server has forgotten about you, you will be told to then disconnect.
Here’s the reference to the bug:
https://github.com/SignalR/SignalR/issues/687