Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identifying SignalR transition from "ConnectionSlow" state to normal state

Tags:

c#

signalr

This document from official doc is a very good start to understand the SignalR lifetime events and states. But something seems to be missing : how can I identify the moment when a connectionSlow switches back to the normal state ?

I want to show a message to the user when the ConnectionSlow event is fired. But I don't know when to hide this message :

  • if the reconnecting event is fired, no problem : I just have to wait for either Reconnected event or Closed event and then either hide the message or display a fatal error.
  • if the reconnecting event is NOT fired, it's perhaps because the connection is returned to a "healthy" state without having to reconnect ==> what should I use to identify this ?

I started to work with the HubConnection class and its StateChanged event, but the ConnectionState enum has no ConnectionSlow state.

like image 636
JYL Avatar asked Feb 02 '26 21:02

JYL


1 Answers

As you've noticed, ConnectionSlow isn't a state, it's just an event that indicates the SignalR client has missed expected keep alive messages.

By default, if the client doesn't receive any keep alives within ~7 seconds of firing ConnectionSlow, it will start attempting to reconnect. So if the client doesn't start reconnecting within 10 seconds of ConnectionSlow firing, you can safely assume that SignalR received a keep alive after ConnectionSlow fired.

This doesn't necessarily mean that the connection is no longer slow, but it does mean that SignalR will wait another ~13 seconds without receiving another keep alive before triggering ConnectionSlow again. This means it takes a total of about 20 seconds with no keep alives before SignalR will automatically try to reconnect. All of these numbers are caclulated using with SignalR's default 10 second keep alive interval.

SignalR's documentation on the Understanding and Handling Connection Lifetime Events goes more in depth.

like image 162
halter73 Avatar answered Feb 04 '26 10:02

halter73