Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signalr stops doing Callbacks after some minutes

I am using signalr 0.4 on an aspx-Page,

var hub = $.connection.FooHub;

hub.disconnected(function () {                
            log("Server has disconnected");
        });

hub.ShowInfo = function (Info) { .... }

$("#Button1").click(function () {
            hub.FooFunction('foo');
        });

$.connection.hub.start();

The Hub is defined as :

public class FooHub : Hub, IDisconnect
{    
    ~FooHub()
    {
        log.Debug("FooHub Destroy");
    }
    public FooHub()
    {
        log.Debug("FooHub Startup");
    }    
    public bool FooFunction(string stuff)
    {
        log.Debug("Hub FooFunction");
        Clients.ShowInfo(someInfo);
        return true;
    }
    public Task Disconnect()
    {
        // Query the database to find the user by it's client id etc. etc.
        MyController.Disconnect(Context.ConnectionId);
        log.Debug("Hub Disconnnect " + Context.ConnectionId);
        return null;
    }
   ......
}

When i open the page and immediately click on Button1
it calls the Hub which in turn calls the ShowInfo-function on the page.
With Firebug i can see that signalr is using long-polling for the communcation. So everything works as expected.

But when i then wait a couple of minutes
i see that

  • FooHub is destroyed
  • Disconnect is called in the Hub,

however on the Page there is no new connection
Firebug shows the old one still being executed
and when i then click on the Button -

  • FooFunction is called (i see a new connection in firebug)
  • FooHub is created
  • FooFunction is executed in the Hub (there is a line in the Log)
  • but ShowInfo is not executed

Is this a bug in SignalR or do i have to do something else to get the ShowInfo-call?

Update (Possible answer):

It was using a Forever-Frame and not long-polling.

In addition, the problem seems to happen mostly when using mobile internet (usb-stick) and Firefox.

Changing the transport to long-Polling seems to fix this issue.

like image 502
Nenad Avatar asked Feb 16 '12 18:02

Nenad


People also ask

Why does SignalR disconnect?

Client disconnection scenarios When the user closes a browser window or tab, or navigates to a new page or refreshes the page, the SignalR connection immediately ends because SignalR client code handles that browser event for you and calls the Stop method.

Does SignalR require sticky session?

SignalR requires that all HTTP requests for a specific connection be handled by the same server process. When SignalR is running on a server farm (multiple servers), "sticky sessions" must be used. "Sticky sessions" are also called session affinity by some load balancers.

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 long polling in SignalR?

SignalR is a Microsoft framework specifically designed to facilitate real-time client/server communication. It provides an effective implementation of long polling that doesn't have a deep impact on the server, and at the same time ensures that clients are appropriately updated about what's going on remotely.


1 Answers

You mention switching to long polling instead of using a forever frame but didn't say how to do that. You can specify which transports to try when starting the connection.

connection.start({ transport: ['longPolling','webSockets'] });

See https://github.com/SignalR/SignalR/wiki/SignalR-JS-Client for more options.

like image 50
Trystan Spangler Avatar answered Nov 15 '22 04:11

Trystan Spangler