SignalR Invoke stops working after Reconnect

1k Views Asked by At

I'm connecting to my SignalR hub via a .Net Client, and invoking a function on the server works fine until the connection is lost from resetting IIS. Once the connection is restored automatically, the Invoke no longer works.

I verified in the web app's logging that the .Net client is successfully reconnecting, and the client's connection state is changing back to Connected. But the Invoke call isn't doing anything. Additionally, if I call Wait() on the invoke, it hangs forever.

Code:

//Works fine before connection lost, but hangs after connection restored
myProxy.Invoke("MyServerFunction", param1).Wait(); 

Any ideas? I should note that this doesn't happen when the client is running locally and connecting to localhost; it only happens when reconnecting to a different server.

2

There are 2 best solutions below

4
On

I am experiencing the same issue, and have checked with wire shark, but there is no outgoing traffic from my hub to my client. The other way around the communication is flowing correctly!

So far I have not been able to establish a solution, but will keep you posted, just wanted to share my findings.

Added tracing to the hub, and the client and noticed that the hub closes the connection, but the client does not. From the Hub logfile:

  SignalR.Transports.TransportHeartBeat Verbose: 0 : d1992c3d-fbec-43e6-9662-b3e94af39418 is dead
  SignalR.Transports.TransportHeartBeat Information: 0 : Removing connection d1992c3d-fbec-43e6-9662-b3e94af39418

And in the logging on the client it keeps using the same connection

02:34:36.3191340 - d1992c3d-fbec-43e6-9662-b3e94af39418 - OnMessage({"I":"232"})

Hover there used to be regular messages of the following type, which are no longer being sent.

02:34:35.2053710 - d1992c3d-fbec-43e6-9662-b3e94af39418 - LP: OnMessage({"C":"d-7D145E50-B,18|N,5|O,1","M":[]})
02:34:35.2073150 - d1992c3d-fbec-43e6-9662-b3e94af39418 - LP Poll: http://172.16.2.101:8074/signalr/poll?clientProtocol=1.4&transport=longPolling&connectionData= ...

from this page Signal R on the wire I learned that the {"I":"232"} message means that:A server void method was completed successfully.

Which is correct, as I can see the updates as they are processed in the hub. But when I invoke a method on that same connection ID nothing happens. And that is not strange as the Hub deemed that connection to be dead!

So why is the connection dead on the hub for outgoing messages, but the hub still able to process incomming messages from that connection?

Additional findings: Here it is mentioned that "client side keep alive check is not utilized for the long polling transport" and I found a reference here that this indeed is disabled by default and the last comment on this issue is "...stops receiving communication coming from server..."

If I understand correctly we enable the client keep alive by setting: GlobalHost.Configuration.KeepAlive And we have set this, so still why does the client not detect connection death!

0
On

Not really the best solution, but I ended up just reinitializing the connection when the state changes to "Reconnecting". Hopefully Garbage Collection will take care of the original connection.

Hopefully this issue will be addressed eventually.