Nir-Z
Nir-Z

Reputation: 869

OnDisconnected method in singalr

I'm using singalr library to develop a real time notification web site using MVC 4.

My web app will run on several web servers so I need to manage connections using a db.

Every thing goes Ok exept that the OnDisconnected method is not fireing in all web browser.

It seems to work fine with firefox but using IE9 and all mobile browsers it nevers fires.

So here's my question, I don't won't to rely on this method and end up with lots of unused connections in my db. Besides, even if the Ondisconnected method will work find there is a chance that the server will go down and these unused connection will remain in the db.

I was thinking of a background method that will run every 1 minute let's say and compare the db's connections against the current connections.

The problem is that I don't know how to implement that or is it the best way to do so. Is there a way to get all valid connection so I can compare with the db?

Thanks in advance

Upvotes: 0

Views: 875

Answers (1)

N. Taylor Mullen
N. Taylor Mullen

Reputation: 18301

The OnDisconnected method should ALWAYS fire for every browser. However, when the OnDisconnected method fires may vary.

Here is the process that SignalR goes through when triggering the OnDisconnected method:

SignalR binds to the unload event of the browser and attempts to send an AJAX request to the server to notify it that the client is going away (disconnecting). IF that AJAX request successfully reaches the server the OnDisconnected method will be triggered immediately. IF that AJAX request fails to reach the server due to network conditions or other unseen conditions then the OnDisconnected will not fire UNTIL the ConnectionTimeout (configuration) has elapsed.

Soooo long story short, OnDisconnected should always eventually fire for every client and every browser. If it does not you should absolutely file an issue on GitHub.

Hope this helps!

Upvotes: 4

Related Questions