Search code examples
c#asp.netsignalrsignalr-hub

SignalR Groups.Add times out and fails


I'm trying to add a member to a Group using SignalR 2.2. Every single time, I hit a 30 second timeout and get a "System.Threading.Tasks.TaskCanceledException: A task was canceled." error.

From a GroupSubscriptionController that I've written, I'm calling:

 var hubContext = GlobalHost.ConnectionManager.GetHubContext<ProjectHub>();
 await hubContext.Groups.Add(connectionId, groupName);

I've found this issue where people are periodically encountering this, but it happens to me every single time. I'm running the backend (ASP.NET 4.5) on one VS2015 launched localhost port, and the frontend (AngularJS SPA) on another VS 2015 launched localhost port.

I had gotten SignalR working to the point where messages were being broadcast to every connected client. It seemed so easy. Now, adding in the Groups part (so that people only get select messages from the server) has me pulling my hair out...


Solution

  • That task cancellation error could be being thrown because the connectionId can't be found in the SignalR registry of connected clients.

    How are you getting this connectionId? You have multiple servers/ports going - is it possible that you're getting your wires crossed?