locked
Hub methods can still be called after the connection was terminated! RRS feed

  • Question

  • User1758761245 posted

    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!

    Wednesday, February 8, 2017 4:58 PM

All replies

  • User-271186128 posted

    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

    Thursday, February 9, 2017 9:45 AM
  • User1758761245 posted

    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.

    Friday, February 10, 2017 5:38 PM
  • User-271186128 posted

    Hi osmiumbin,

    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

    Saturday, April 1, 2017 7:10 AM