Signalr stops making callbacks after a few 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(); 

A 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 client id etc. etc. MyController.Disconnect(Context.ConnectionId); log.Debug("Hub Disconnnect " + Context.ConnectionId); return null; } ...... } 

When I open the page and immediately click Button1
it calls the hub, which in turn calls the ShowInfo function on the page.
With Firebug, I see that signalr uses lengthy polling for switching. So, everything works as expected.

But when I wait a couple of minutes
I see that

  • FooHub destroyed
  • The shutdown is called in the hub,

however, there is no new connection on the page
Firebug shows an old one that is still running
and when I then click -

  • FooFunction is called (I see a new connection in firebug)
  • Created by FooHub
  • FooFunction is executed in the hub (there is a line in the log)
  • but showinfo fails

Is this a bug in SignalR or do I need to do something else to get a ShowInfo call?

Update (possible answer):

He used Forever-Frame and not a lengthy survey.

In addition, the problem seems to occur most often when using the mobile Internet (usb-stick) and Firefox.

Changing the migration to long-polling seems to fix this problem.

+6
source share
2 answers

You are talking about switching to a lengthy survey instead of using an eternal frame, but you did not say how to do it. You can specify which transports to try when starting a connection.

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

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

+1
source

Have you looked at this https://github.com/SignalR/SignalR/wiki/Configuring-SignalR Try looking at this. For me, as your code, everything seems to be OK. You can also check this in Chrome and see what happens.

0
source

Source: https://habr.com/ru/post/908647/


All Articles