Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signal R randomly loses connection to the server side

We use Signal R with an Azure web app in an ASE for our real time web application. We noticed that Signal R sometimes looses connection to the hub in no particular pattern. This happens both during high traffic periods as well as low traffic ones but I am more interested in why this i happening during low traffic periods. Note: We have a so called "1-minute auto refresh" which is triggered by the JavaScript on the page. That seems to be working.

Anyone experienced similar issues using SignalR, and if so, how did you resolve this?

Thank you (a tester, don't be too harsh!lol )

like image 584
Iren Avatar asked May 16 '17 11:05

Iren


1 Answers

I have definitely experienced this, and it drove me nuts.

By default, a SignalR client will try to reconnect for 20 seconds after losing connection to its Hub. After 20 seconds without a successful reconnect, the disconnected event is raised on JavaScript clients. After disconnected is raised, the client will give up trying to reconnect and the connection is dead. This page describes SignalR lifecycle events and offers some code on trying to reconnect after the disconnected event is raised.

Now as to why this happens. I've noticed that an App Pool recycle can take longer than 20 seconds in some apps, which can lead to a disconnected event. Intermittent drops in network connectivity between your JavaScript clients and Hub that lasts more than 20 seconds can cause this also. The bottom line is that things can go wrong that are beyond your control and you cannot code around them. Therefore, put in place the logic to attempt to reconnect after your JavaScript client receives the disconnected event.

like image 73
Rob Reagan Avatar answered Nov 15 '22 09:11

Rob Reagan