I'm faced with a strange behavior with signalR. I use it only on one component (vue.js on my ui). When the user navigates to another page (I have spa application) in a destroyed event I'm trying to close the connection. I'm trying two options:
JS: connection.stop();
BE: i catch disconnect message in public override Task OnDisconnectedAsync method
or
JS: connection.invoke('Resource', params);
BE: await Groups.RemoveFromGroupAsync(Context.ConnectionId, "<group name>");
The connection is closed successfully but after some time (~15-20 seconds) the signalR is trying to connect to the server again (but the component is not existing in the elements block). After some time connection was restored but this component is not existing. If i refresh my spa page (with F5) signalR is not trying to connect, but if i open the component with signalR the situation is starting again.
Maybe somebody can help me with:
I found it. I've created an empty Disconnect handler and trying to catch the connections.
public override Task OnDisconnectedAsync(Exception? exception) { //breakpoint here; }
Some dev is added another SignalR hub on the application (e.g. another component on UI) and forgets to call close on component unload.
this.connection.stop()
So, don't forget to stop SignalR connections between UI and backend server.