Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR: Is it necessary to remove the connection id from group OnDisconnect()?

Tags:

signalr

The tutorials only covered adding a connection ID to the group on OnConnected(), but what about cleaning it up on OnDisconnect()?

After a permanent loss of connectivity, a client is given a new connection ID. What happens to its old connection ID in the group list? Is it automatically cleaned up? or is it scalable enough that I don't have to worry about it?

like image 214
Yorro Avatar asked May 25 '14 11:05

Yorro


People also ask

How many groups can SignalR handle?

Yes, it will work since the Microsoft documentation says that you can create 1 group per user/connection, so it depends by user limit and not group limit. So if your SignalR service can handle 40k+ users, it will handle 40k+ groups.

How do I stop SignalR connection?

A SignalR connection can end in any of the following ways: If the client calls the Stop method, a stop message is sent to the server, and both client and server end the SignalR connection immediately.

How do I add a user to group SignalR?

Adding and removing users To add or remove users from a group, you call the Add or Remove methods, and pass in the user's connection id and group's name as parameters. You do not need to manually remove a user from a group when the connection ends.


1 Answers

According to the statement here, you don't need to remove connections from groups:

You should not manually remove the user from the group when the user disconnects. This action is automatically performed by the SignalR framework.

When a connection subscribes to a topic (which happens when you add the connection to a group), it receives a disposable which will remove the subscription when disposed (which means the connection isn't in the group anymore). This is triggered when a connection disconnects and is removed.

like image 59
Lars Höppner Avatar answered Sep 21 '22 17:09

Lars Höppner