Setup: Self hosted SignalR server (console) + web client application.
Scenario: If i start debugging the client javascript code (breakpoint or a 'debugger;') and wait for 30+ seconds without any call to the server, the OnDisconnected event is fired on the server (which is correct) but not on the client ( which is also correct
i assume, since the js is not running in this time) but after that if i continue the client execution i am able to call server hub methods from the already 'terminated' connection. Is this normal? How can i prevent that from happening after the OnDisconnected
event fired? I was expecting the connection to be disposed and the request to never reach the server prior to starting a new connection.
From my understanding there are two events that fire after 'DisconnectTimeout' is reached. The server side OnDisconnected and the client javascript timeout which stops and probably disposes the connection so any server call would actually result in a js
error. Please let me know if this is a known issue or how can i fix it?
Perhaps it re-connect, you could call the stop() method to stop the connection. More details, I suggest you take a look at this article to check the Connection Lifetime Events in SignalR.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Thanks for the reply. For some strange reason i cannot reproduce the issue anymore. What i get now is that while the JS is paused in the browser the connection is not lost so the server OnDisconnected is not called. After resuming the JS, all the requests
that were supposed to go to the server are sent (probably queued?) and if the pause took more than the disconnect timeout, it closes the client connection so any other request cannot go through anymore. On the server, after the disconnect timeout, the OnDisconnected
method is called (stopCalled = false) and the connection is terminated on the server side. No reconnection will happen though. So in this case the total time needed to terminate the connection on the server side is JS pausing time + disconnect timeout (default
30 sec).
I was expecting that the connection to be terminated on the server during the debugging period since the JS execution is paused (therefore unresponsive), but i guess that's not an issue.
How can i prevent that from happening after the OnDisconnected event fired?
As far as I know, SignalR version 2 does not have a built-in server API for disconnecting clients or preventing clients from calling hub methods. If you’d like to prevent clients from calling hub methods after the OnDisconnected event fired, you could try
to define a function and call $.connection.hub.stop() on the client, and then you could call that function from the server to stop a connection.
Best regards,
Dillion
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
5 Points
33 Posts
Hub methods can still be called after the connection was terminated!
Feb 08, 2017 04:59 PM|osmiumbin|LINK
Hello, i'm facing the following problem:
Setup: Self hosted SignalR server (console) + web client application.
Scenario: If i start debugging the client javascript code (breakpoint or a 'debugger;') and wait for 30+ seconds without any call to the server, the OnDisconnected event is fired on the server (which is correct) but not on the client ( which is also correct i assume, since the js is not running in this time) but after that if i continue the client execution i am able to call server hub methods from the already 'terminated' connection. Is this normal? How can i prevent that from happening after the OnDisconnected event fired? I was expecting the connection to be disposed and the request to never reach the server prior to starting a new connection.
From my understanding there are two events that fire after 'DisconnectTimeout' is reached. The server side OnDisconnected and the client javascript timeout which stops and probably disposes the connection so any server call would actually result in a js error. Please let me know if this is a known issue or how can i fix it?
Thanks!
All-Star
45489 Points
7008 Posts
Microsoft
Re: Hub methods can still be called after the connection was terminated!
Feb 09, 2017 09:45 AM|Zhi Lv - MSFT|LINK
Hi osmiumbin,
Perhaps it re-connect, you could call the stop() method to stop the connection. More details, I suggest you take a look at this article to check the Connection Lifetime Events in SignalR.
https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/handling-connection-lifetime-events
Best regards,
Dillion
Member
5 Points
33 Posts
Re: Hub methods can still be called after the connection was terminated!
Feb 10, 2017 05:38 PM|osmiumbin|LINK
Hello Zhi Lv,
Thanks for the reply. For some strange reason i cannot reproduce the issue anymore. What i get now is that while the JS is paused in the browser the connection is not lost so the server OnDisconnected is not called. After resuming the JS, all the requests that were supposed to go to the server are sent (probably queued?) and if the pause took more than the disconnect timeout, it closes the client connection so any other request cannot go through anymore. On the server, after the disconnect timeout, the OnDisconnected method is called (stopCalled = false) and the connection is terminated on the server side. No reconnection will happen though. So in this case the total time needed to terminate the connection on the server side is JS pausing time + disconnect timeout (default 30 sec).
I was expecting that the connection to be terminated on the server during the debugging period since the JS execution is paused (therefore unresponsive), but i guess that's not an issue.
All-Star
45489 Points
7008 Posts
Microsoft
Re: Hub methods can still be called after the connection was terminated!
Apr 01, 2017 07:10 AM|Zhi Lv - MSFT|LINK
Hi osmiumbin,
As far as I know, SignalR version 2 does not have a built-in server API for disconnecting clients or preventing clients from calling hub methods. If you’d like to prevent clients from calling hub methods after the OnDisconnected event fired, you could try to define a function and call $.connection.hub.stop() on the client, and then you could call that function from the server to stop a connection.
Best regards,
Dillion