OnDisconnect and ClientTimeoutInterval documentation unclear and somewhat misleading
Description
There is detailed documentation the describes how the OnDisconnect function is called (referencing net core version) when a connection is broken and the ClientTimeoutInterval is exceeded. However, in my testing with breakpoints, if I open a connection and then close the browser I have not seen a disconnect being called in 5 minutes when I have set the configuration for ClientTimeoutInterval to 30 seconds. The only documentation on this sort of hand waves an explanation saying "this could longer" but not defining what longer is, exactly.
The server considers the client disconnected if it hasn't received a message (including keep-alive) in this interval. It could take longer than this timeout interval for the client to be marked disconnected due to how this is implemented. The recommended value is double the KeepAliveInterval value.
I have a use case where it is valuable for clients to have knowledge of the connection status of other clients (a friend's list). It's helpful to show a person is offline when they no longer have connection to the server. I was hoping to be able to piggyback off of the system already written into SignalR instead of re-inventing the wheel. Looking through stack overflow, it seems like there are others with the same thinking on this issue. Now, I don't object to the design decisions that needed to be made for SignalR to work, but it would be helpful if the functionality was clearer. I spent quite a bit of time trying to get the OnDisconnect to fire when a connection was broken without calling the close() method, and haven't been able to trigger one yet. It seemed like that was a reasonable expectation based on the documentation, method names, and configuration options.
An update to the documentation that makes it a little more clear that OnDisconnect isn't a timely way to update user online status, or a way to clean up any server resources from a connection within a predictable timeframe would be appreciated.
Page URL
https://learn.microsoft.com/en-us/aspnet/core/signalr/configuration?view=aspnetcore-7.0&tabs=javascript#configure-server-options
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/signalr/configuration.md
Document ID
66d252c3-6300-7e28-9aa0-ef2ff66e7a76
Article author
@bradygaster
@BrennanConroy, Is there a way I should change this statement, so it is a bit clearer for this situation?
ClientTimeoutInterval
"The server considers the client disconnected if it hasn't received a message (including keep-alive) in this interval. It could take longer than this timeout interval for the client to be marked disconnected due to how this is implemented. The recommended value is double the KeepAliveInterval value."
in my testing with breakpoints
The problem they're having is that some timeouts are disabled when running under the debugger. https://github.com/dotnet/aspnetcore/issues/41673
That would explain it. I went ahead and made my own timeout system as I need to be able to test this functionality during development. As others commented in the thread, timeouts during development could be handled with configuration parameters. That would help my case.
If, in the future, this is allowed in development I can revisit replacing my own solution.