Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 333
SiberianGuy Avatar asked Aug 28 '15 10:08

SiberianGuy


People also ask

Why does SignalR disconnect?

If a server does not become available within the disconnect timeout period, the SignalR connection ends. In this scenario, the Closed event ( disconnected in JavaScript clients) is raised on the client but OnDisconnected is never called on the server.

How do I check if my SignalR is reconnecting?

To test reconnect after the server goes down use iisreset. To simulate client connection dropping (good luck) pull the network cable :) Pulling the network cable won't accurately simulate a client connection dropping when you're using Azure SignalR Service.

How do I stop SignalR connection?

hub. stop(). done(function() { alert('stopped'); });

How do I set SignalR connection timeout?

Timeout configuration for SignalR can be set in Application_Start method of Global class in Global. asax. cs file. // Wait a maximum of 30 minutes after a transport connection is lost // before raising the Disconnected event to terminate the SignalR connection.


1 Answers

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.

like image 116
Amirhossein Mehrvarzi Avatar answered Sep 28 '22 15:09

Amirhossein Mehrvarzi