Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SignalR Client Disconnected Event not called when internet connection is lost #3919

Closed
jakeb16 opened this issue Apr 28, 2017 · 8 comments
Closed

Comments

@jakeb16
Copy link

jakeb16 commented Apr 28, 2017

Expected behavior

The $.connection.hub.disconnected should get called after 30 seconds of the client not being able to talk to the server

Actual behavior

It keeps trying to reconnect indefinitely

Steps to reproduce

Handel all the events

$.connection.hub.connectionSlow = function(){console.log("[" + (new Date()).toString() + "] SignalR Connection Slow");};
$.connection.hub.reconnecting = function(){console.log("[" + (new Date()).toString() + "] SignalR Connection Reconnecting"); };
$.connection.hub.reconnected = function(){console.log("[" + (new Date()).toString() + "] SignalR Connection Reconnected");};
$.connection.hub.disconnected = function(){console.log("[" + (new Date()).toString() + "] SignalR Connection Disconnected"); };
$.connection.hub.stateChanged = function () { console.log("[" + (new Date()).toString() + "] SignalR StateChange");
$.connection.hub.logging = true;

Connect with Start

Turn off wifi or pull the plug on the internet

This is the only thing that shows in the logs, the disconnected event is never fired.

In Chrome
XHR failed loading: POST "http://xxxxxxxx/signalr/poll?transport=longPolling& net::ERR_INTERNET_DISCONNECTED

In IE11
[18:02:51 GMT-0700 (US Mountain Standard Time)] SignalR: Opening long polling request to 'http://xxxxxxx/signalr/reconnect?transport=longPolling&clientProtocol=1.5&connectionToken=cvKizCrqc3saz0gQuNvTaMeB91jkPeVOP4cBz3ZDgzdsi7iQm4aC25dBr%2BxjWwEetYS8PEh0jlVuu9Q0UL9RUzBD4klYw3EBhYgP10p0wcBccPYY0BW%2BSH4EyPxff2AaSBsAfrqsJBiUTrbA5DV7Jw%3D%3D&connectionData=%5B%7B%22name%22%3A%22realtimeinboxhub%22%7D%5D'.
SCRIPT7002: XMLHttpRequest: Network Error 0x2ee7, Could not complete the operation due to error 00002ee7.

Note we are not using web sockets

With Forever frames we see this, but still no disconnected event is raised on the client
[18:30:15 GMT-0700 (US Mountain Standard Time)] SignalR: Keep alive has been missed, connection may be dead/slow.
[18:30:22 GMT-0700 (US Mountain Standard Time)] SignalR: Keep alive timed out. Notifying transport that connection has been lost.

[18:30:24 GMT-0700 (US Mountain Standard Time)] SignalR: Updating iframe src to 'http://xxxxx/signalr/reconnect?transport=foreverFrame&groupsToken=vdn69Z4r7I2HFeyiTwC7V06mYy4t0P67Y5yDr9HGQjhISisu0%2B484DIW9G0eV33yAqp1TQ8vgH4L07UQ3Uor%2BAC2FGNsLrH7OEyigVMVsocgSvSzQUmzpStCDvNG2ir3qiOl4ITLOuIKQREA%2B%2BUNRg%3D%3D&messageId=s-0%2C3979&clientProtocol=1.5&connectionToken=KlY0U0ZuDWgNrsUdhGWsyO2%2FKk1ltTvvDI25ncWYV%2FZN%2BSR9MufllEMiDSZXjNAkHy%2Be21M7dUXx8%2BSOb%2BqoTf2ZUA3c%2FStYpbJSCv6XBkgKgDKrQd9hKZoW1KTTlVEWN7g9VClztVn1N2Y4FBBLFA%3D%3D&connectionData=%5B%7B%22name%22%3A%22realtimeinboxhub%22%7D%5D&tid=2&frameId=1'.

[18:30:24 GMT-0700 (US Mountain Standard Time)] SignalR: Forever frame iframe finished loading and is no longer receiving messages.

@jakeb16
Copy link
Author

jakeb16 commented Apr 28, 2017

FYI I am connecting from a different computer than the server, unlike the last person who had this same problem.

@moozzyk
Copy link
Contributor

moozzyk commented Apr 28, 2017

There is no reliable method of detecting that the cable has been unplugged and pending HTTP requests might not be terminated if this happens. Longpolling transport is the only transport that does not have keep alive (we tried adding it and it caused more problems than it solved). There is a poll timeout of 120 seconds after which client should try re-poll which should fail because new HTTP requests - as you noticed - cannot be make. This should lead to reconnects. Also, reconnects are not indefinite - if the client cannot reconnect within a timeout the connection will be closed.

@jakeb16
Copy link
Author

jakeb16 commented Apr 28, 2017

@moozzyk Thanks for your quick response! I appreciate it.
I totally get what your saying but thats not what I am seeing, here is a log of signalR trying to reconnect for 10 minutes.

Here is the code that I am using to generate the log

            $.connection.hub.connectionSlow = function(){console.log("[" + (new Date()).toString() + "] SignalR Connection Slow");};
            $.connection.hub.reconnecting = function(){console.log("[" + (new Date()).toString() + "] SignalR Connection Reconnecting"); };
            $.connection.hub.reconnected = function(){console.log("[" + (new Date()).toString() + "] SignalR Connection Reconnected");};
            $.connection.hub.disconnected = function(){console.log("[" + (new Date()).toString() + "] SignalR Connection Disconnected"); };
            $.connection.hub.stateChanged = function () { console.log("[" + (new Date()).toString() + "] SignalR StateChange") };
            $.connection.hub.logging = true;
            RealTimeInboxConect();

 function RealTimeInboxConect() {
            console.log("[" + (new Date()).toString() + "] SignalR RealTimeInboxConect");
            var defered = $.connection.hub.start({ transport: ['foreverFrame', 'serverSentEvents'] });
            defered.fail(function () {
                console.log("[" + (new Date()).toString() + "] SignalR Failed to start Attempt:");                
                setTimeout(function () {
                    RealTimeInboxConect();
                }, 1000);
            });
            defered.done(function () {
                console.log("Done Connectiong");
                $('#sendmessage').click(function () {
                    // Call the Send method on the hub.
                    chat.server.send($('#displayname').val(), $('#message').val());
                    // Clear text box and reset focus for next comment.
                    $('#message').val('').focus();
                });
            });
        }

SignalRLog.txt

@moozzyk
Copy link
Contributor

moozzyk commented Apr 28, 2017

foreverFrame needs to be investigated then. The client should give up reconnecting if it could not re-establish connection within reconnect timeout/window.

@jakeb16
Copy link
Author

jakeb16 commented Apr 28, 2017

The problem is its not just foreverFrame, its sse and long polling as well, here are some more logs for each of those.
Note all I am doing to repro is disabling wifi

SignalRLogSSE.txt
SignalRLogLongPolling.txt

@jakeb16
Copy link
Author

jakeb16 commented Jun 15, 2017

I'm new to Gethub so sorry if this is the wrong place, but what happens to this form here?
I need a way to tell the UI that the signalR connection has stopped, the problem is if for example the app pool where the hub resides stops, it just goes into a infinite loop and without calling any client code to let me know that the connection is broken.

Any suggestions on how to report the status of the connection to the UI?

@jakeb16
Copy link
Author

jakeb16 commented Jun 16, 2017

A co-worker finally pointed me to the problem I was overriding the handlers instead of passing my function to them

$.connection.hub.disconnected = function(){console.log("[" + (new Date()).toString() + "] SignalR Connection Disconnected"); };

vs
$.connection.hub.disconnected( function(){console.log("[" + (new Date()).toString() + "] SignalR Connection Disconnected"); });

@aspnet-hello
Copy link

This issue has been closed as part of issue clean-up as described in https://blogs.msdn.microsoft.com/webdev/2018/09/17/the-future-of-asp-net-signalr/. If you're still encountering this problem, please feel free to re-open and comment to let us know! We're still interested in hearing from you, the backlog just got a little big and we had to do a bulk clean up to get back on top of things. Thanks for your continued feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants