SignalR Error When Closing Web Socket - Invalid handle

This SignalR problem occurs:

Error closing web socket: System.Net.WebSockets.WebSocketException (0x80070006): handle is invalid

I think the problem is with this code:

var currentHub = GlobalHost.ConnectionManager.GetHubContext<HubManager>(); currentHub.Groups.Remove(userConnectionId, roomName); 

How can this be fixed?

+6
source share
1 answer

I had the same problem. It started when I added SQL Backplane to signalR,

This is due to the "Freshness" of the hub context, which I did:

  /// <summary> /// In case a backplane is used (in case of load balancer) , the instance should always be taken fresh /// if no backplane is used no need to refresh the instance on each invocation public class HubContextService { bool BackplaneUsed { get; set; } IHubContext _context = null; public HubContextService(bool isBackPlaneUsed = true) { BackplaneUsed = isBackPlaneUsed; } public IHubContext HubContext { get { if (BackplaneUsed) { return GlobalHost.ConnectionManager.GetHubContext<HubManager>(); } else { if (_context == null) { _context = GlobalHost.ConnectionManager.GetHubContext<HubManager>(); } return _context; } } set { _context = value; } } } 
+1
source

All Articles