3

We created a self-host SignalR server and our WPF Desktop application is connecting to that server. We are just doing login-logout management, everything is simple and working. But after sometime, usually 2-3 hours, half of the client are disappearing from online clients list.

It appears that, OnDisconnected event is triggered on server for connections, even though they are not closed. After OnDisconnected event, these connections can still send and receive data.

Is there any scenario that causes to OnDisconnected event triggered on server when connection is not closed?

doobop
  • 4,465
  • 2
  • 28
  • 39

1 Answers1

1

Is there any scenario that causes to OnDisconnected event triggered on server when connection is not closed?

Yes. If connection is timed out, first disconnect then reconnect occurs (if the client don't close the connection explicitly).

public override System.Threading.Tasks.Task OnDisconnected(bool stopCalled)
{
    if (stopCalled)
    {
        Console.WriteLine(String.Format("Client {0} explicitly closed the connection.", Context.ConnectionId));
    }
    else
    {
        Console.WriteLine(String.Format("Client {0} timed out .", Context.ConnectionId));
    }

    return base.OnDisconnected();
}

As you can see here. If explicitly disconnect occurs (stopCalled is true), client is disconnected for sure and reconnect will not occur.

if client is really not disconnected, after disconnect reconnect can occur like in your stuation.

Check here fore more detail

Community
  • 1
  • 1
Erkan Demirel
  • 4,302
  • 1
  • 25
  • 43
  • 1
    Thank you for the answer, we didn't do any control on OnReconnected event, that was the problem i guess. – Mustafa uçar Apr 06 '16 at 11:16
  • 1
    please check uniqueness of connection Id (If you keep them) on Reconnected. Iif reconnect occurs without disconnect occurs you may ,have duplicate records. Check here http://www.asp.net/signalr/overview/guide-to-the-api/mapping-users-to-connections – Erkan Demirel Apr 06 '16 at 11:23