Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you need to manually remove a connection from a SignalR group on disconnect?

In a SignalR hub, I am adding connections to groups in the OnConnected method:

public override Task OnConnected()
{
    this.Groups.Add(this.Context.ConnectionId, "aGroup");
    this.Groups.Add(this.Context.ConnectionId, "bGroup");
}

Do I need to manually remove the connection from these groups upon disconnect? Given the pub-sub model, I don't see how I could easily do this, except to keep track of connections and groups in a separate data structure.

I am experiencing a rather large memory leak in an MVC project using SignalR, and am wondering if this could be the culprit.

like image 245
Dave Mateer Avatar asked Sep 11 '15 14:09

Dave Mateer


People also ask

How do I disconnect from SignalR?

SignalR version 2 does not have a built-in server API for disconnecting clients. There are plans for adding this functionality in the future. In the current SignalR release, the simplest way to disconnect a client from the server is to implement a disconnect method on the client and call that method from the server.

How many connections SignalR can handle?

In the default mode, the app server creates five server connections with Azure SignalR Service. The app server uses the Azure SignalR Service SDK by default. In the following performance test results, server connections are increased to 15 (or more for broadcasting and sending a message to a big group).

Does SignalR require sticky session?

SignalR requires that all HTTP requests for a specific connection be handled by the same server process. When SignalR is running on a server farm (multiple servers), "sticky sessions" must be used. "Sticky sessions" are also called session affinity by some load balancers.


1 Answers

No, you don't.

You don't have to explicitly create groups. In effect, a group is automatically created the first time you specify its name in a call to Groups.Add, and it is deleted when you remove the last connection from membership in it.

Source, and read further: http://www.asp.net/signalr/overview/guide-to-the-api/working-with-groups

like image 86
DDan Avatar answered Sep 20 '22 15:09

DDan