Search code examples
signalrsignalr-hub

SignalR in .NET 5.0 not detecting abrupt disconnections


I am running a SignalR Hub in .NET 5.0 in a Docker container. I am using the inbuild SignalR package for .NET 5.0. It is failing to detect abrupt disconnections. If I instruct SignalR to drop the connection from client-side, it detects the disconnection, but if I just close the browser SignalR doesn't detect the disconnection.

This is the functional equivalent of the code I am using to detect disconnections.

public override async Task OnDisconnectedAsync(Exception exception)
{
    var userId = Map.GetUserFromMapping(Context.ConnectionId
    Map.Unmap(userId, Context.ConnectionId);
    await base.OnDisconnectedAsync(exception);
}

I know this problem existed in AspNetCore 2.1 and earlier versions, but I understood that this problem was supposedly fixed in later versions.

Why are the abrupt disconnection not being detected? What factors could/would be affecting this?


Solution

  • Solved my own problem. My setup was falling back on Long-Polling which doesn't have keep alive functionality and therefore doesn't detect disconnections.