Open ZhiqingWan opened 3 years ago
I'll see if SignalR protocol could support this.
How'd you get on with this @terencefan?
My use case is a chat app. If two users are chatting and one closes the browser, the OnDisconnectAsync method is called and the chat is marked as stopped. OnDisconnectAsync is also fired if a user is experiencing connectivity issues - in those cases I don't want to mark the chat as stopped as the client will attempt to reconnect and the chat can be continued if that is successful.
At present, because this Exception is not passed through (despite the docs saying it should be) there is no easy way to handle these two cases separately. IIRC, the exception was passed through correctly in SignalR for .NET Framework using ASRS but maybe I was mistaken; I've just migrated from that version.
Any further updates on this one?
Has someone been able to look in to whether this can be supported on ASRS? If not, I really need some direction on how to differentiate on the server side between a disconnection that occurs due to the client closing their browser vs a client losing their internet connection. @vicancy, is this something you could help with?
Sorry for the late response.
differentiate client disconnection due to closing their browser vs a client losing their internet connection
When client "loses internet connection", SignalR hub leverages the SignalR client ping messages to determine if the client is still there, however SignalR swallows the OperationCancelledException https://github.com/dotnet/aspnetcore/blob/88ee825bca9978df7f1d8c8c09b71b6dffeeb53b/src/SignalR/server/Core/src/HubConnectionHandler.cs#L169 and as a result it fails to differentiate from these 2 conditions and here is the issue https://github.com/dotnet/aspnetcore/issues/26701
In such a scenario, the Azure SignalR acts as a proxy and there is little Azure SignalR can do to change the behavior in SignalR application layer.
Describe the bug
When that OnDisconnect method is called, it appears as though there is no Exception passed through, so there's no way to differentiate between a user that has just closed their browser, or a user that has been experiencing connectivity issues. SignalR for .NET Framework would pass through a boolean informing the server that it was as a result of a timeout.
To Reproduce
Exceptions (if any)
Further technical details
Microsoft.AspNetCore.SignalR