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

Yorro picture Yorro · May 25, 2014 · Viewed 7.6k times · Source

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?

Answer

Lars Höppner picture Lars Höppner · May 29, 2014

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.