SiberianGuy
SiberianGuy

Reputation: 25282

SignalR weird reconnect pattern

I'm working with SignalR under very specific set of network conditions (a crazy proxy). So sockets do not work at all and I have to use long-polling. When I refresh a page it seems to work for a while but then the first Disconnect happens. I'm trying to automatically reconnect on disconnected event and the following pattern:

  1. After the page is loaded, hub disconnects in about 110 seconds (default timeout)
  2. It takes 3 Disconnected events to restart a hub after the first disconnect (so it connects only on the 4th try)
  3. After that it always reconnects on the 1st try but disconnects after about 10-15 seconds (not 110 seconds). So it looks like keep-alive timeout is somehow involed here (while it wasn't on the first try).

This behaviour seems weird. Is there anything I can do to improve it?

Upvotes: 11

Views: 715

Answers (2)

Manraj
Manraj

Reputation: 494

Use ConnectionStatusStream. This stream OnNexts when the client side SignalR hub proxy events are raised. So we see thing like Connecting, Connected,ConnectionSlow, Reconnecting,Reconnected,Closed,Uninitialized. All of which started out life as events on the SignalR hub proxy, and are turned in to an IObservable stream using one of the many RX factories. In this case IObservable.FromEvent.

Anyway here is the overall ConnectivityStatusViewModel that we use to show the information in the bottom status bar of the app.

Refer this:

ConnectionStatusStream

Upvotes: 2

Amirhossein Mehrvarzi
Amirhossein Mehrvarzi

Reputation: 18944

Assume the tips available in Understanding and Handling Connection Lifetime Events in SignalR where you can employ good solutions to handle connection lifetime based on the network problem. Furthermore, In SignalR's issues I found the following solution for you which works with long-polling too.

You can set the KeepAlive property on the ConfigurationManager and SignalR will send an empty frame of data (based on the transport) on the specified interval to keep the connection alive (look at Allow host to specify keep alive times). The current time-out mechanism makes the streaming protocols no different.

Upvotes: 2

Related Questions