Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR Stops Working After A While

For some reason, SignalR will just stop calling client methods after a short period of time (about 1 hour or less I estimate). I have a page that shows Alerts... a very simple implementation. Here's the Javascript:

$(function () {

    // enable logging for debugging
    $.connection.hub.logging = true;

    // Declare a proxy to reference the hub. 
    var hub = $.connection.alertHub;

    hub.client.addAlert = function (id, title, url, dateTime) {
        console.log(title);
    };

    $.connection.hub.start().done(function () {
        console.log("Alert Ready");
    });
});

If I refresh the page, it works again for about an hour, then will stop calling the client event addAlert. There are no errors in the log, no warnings. The last event in log (other than the pings to the server) is:

[15:18:58 GMT-0600 (CST)] SignalR: Triggering client hub event 'addAlert' on hub 'AlertHub'.

Many of these events will come in for a short while, then just stop, even though the server should still be sending them.

I am using Firefox 35.0.1 on Mac and SignalR 2.0.0.

I realize that a work-around is to force a page refresh every 10 mins or so, but I'm looking for a way to fix the root cause of the problem.

I enabled SignalR tracing on the server. I created an "alert" on the server after a fresh refresh of the Alert page and the alert came through. I waited about 10 mins and I tried it again, and it failed to come through. Here's what the logs read (sorry for the verbosity, not sure what was relevant):

SignalR.Transports.TransportHeartBeat Information: 0 : Connection b8b21c4c-22b4-4686-9098-cb72c904d4c9 is New.
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(b8b21c4c-22b4-4686-9098-cb72c904d4c9)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(b8b21c4c-22b4-4686-9098-cb72c904d4c9)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(b8b21c4c-22b4-4686-9098-cb72c904d4c9)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(b8b21c4c-22b4-4686-9098-cb72c904d4c9)

There are dozens more of the SignalR.Transports.TransportHeartBeat messages, but nothing else.

like image 671
Swisher Sweet Avatar asked Feb 23 '15 21:02

Swisher Sweet


People also ask

Why does SignalR disconnect?

A SignalR connection can end in any of the following ways: If the client calls the Stop method, a stop message is sent to the server, and both client and server end the SignalR connection immediately.

How many connections SignalR can handle?

In the default mode, the app server creates five server connections with Azure SignalR Service. The app server uses the Azure SignalR Service SDK by default. In the following performance test results, server connections are increased to 15 (or more for broadcasting and sending a message to a big group).

What is forever frame SignalR?

Forever Frame (for Internet Explorer only). Forever Frame creates a hidden IFrame which makes a request to an endpoint on the server that does not complete. The server then continually sends script to the client which is immediately executed, providing a one-way realtime connection from server to client.

Does SignalR need SSL?

If your SignalR application transmits sensitive information between the client and server, use SSL for the transport.


1 Answers

i think theres a timeout of default 110 seconds for signalr. Can you try signalr disconnected event to reconnect it back.

$.connection.hub.disconnected(function () {
            setTimeout(function () {
                startHub();
            }, 5000);
        });

and in startHub() you can start connection again.

reference : https://github.com/SignalR/SignalR/issues/3128

and How to use SignalR events to keep connection alive in the right way?

like image 191
Chaitanya Gadkari Avatar answered Oct 13 '22 07:10

Chaitanya Gadkari