Signalr firing multiple OnDisconnect calls and the connection is not disconnected either

Viewed 599

We have a scaled out(2 instances) Azure Cloud deployed asp.net Web API based SignalR hub server, which acts as a go between for devices and their mobile users. Almost a Chat scenario.

We're seeing multiple OnDisconnected calls for some connections although the connections are alive. Basically although the server is seeing multiple OnDisconnected calls fired on itself for a connection, the client is still alive able to make calls and it continues to use the same single connection with the same signalr connectionID.

Its as if the client has no impact of the OnDisconnected called on the server. The client uses websockets.

We do some operations in the OnDisconnected(basically tracking the connections) and that is going haywire because of this. Our code is encapsulated inside try/catch blocks and lets the base.OnDisconnected run irrespective. Looked at the signalr code, but can't make out how this is possible.

Any help will be greatly appreciated. We're using: Signalr 2.2.2.

1 Answers

Are you using some form of backplane to manage your state? If so it looks that your connection ID's are not being synced between requests. onDisconnect will fire even if the connection is slow and unresponsive but not disconnected, this is determined by that timeout value you are using. There will also be scenarios where you will disconnect without onDisconnect ever being fired, onDisconnected is a best case scenario most of the time. If you need to do some work based on a disconnect then you are likely better off using a polling strategy to determine if a user is still connected.

Related