-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
How to detect loss of network connection client-side in Chrome #259
Comments
Hi there. Thanks for the detailed, clear report- that was very welcome. Just have my hands full today so haven't confirmed, but think you've identified a bug here related to #230. Basically: #230 addressed the problem on the server side, and looks like we'll need an equivalent strategy on the client end to reliably identify these kinds of sudden disconnects across all browsers/devices. Didn't realise Chrome behaved this way. Since we already have the server broadcasting pings at the necessary interval, we just need to mod the client with a simple timer to check if it's received any comms from the server w/in a timeout window. Should be a simple fix, just fully occupied for the next week or two. Will try get to this asap.
That sounds reasonable as a workaround so long. Cheers! |
Quick note if you're not against running a fork so long- it might be easier for you to just use the built-in pings. You'll need to fork to make them available to your app: |
Quick sketch of a possible implementation. Didn't test, or think about this much. Situation before #230: Clients maintain keep-alive, sending pings to server. On sudden conn break (e.g. airplane mode), clients would know about the break but the server wouldn't Situation after #230: Server maintains keep-alive, sending pings to clients. On sudden conn break (e.g. airplane mode), server would know about the break but clients wouldn't. As of this commit: Server and clients each maintain a keep-alive[1]. I.e. each side will attempt to ping if it hasn't heard from the other side in a prescribed window. On sudden conn break, each side will be made aware of the break when its own scheduled window fires and fails to successfully send a ping. [1] Timeouts should be different. In particular, the client may like to choose a much more aggressive window (e.g. 5s) to provide a rapid indicator to users.
Sounds good. Thanks for confirming that I wasn't overlooking an existing config or other solution for this particular situation. I'll read through the current Sente Thank you again for the timely response. This is the first project I've used Sente in and it's been a great experience (especially with the help of the awesome readme and all the examples). |
Please note that a pong response isn't what you want since when the connection's down, the client won't receive the ping (pong response). Had a free moment yesterday so quickly sketched out one approach at 7ef5971 Entirely untested, but may give you a starting point if you want to do your own pings. Basically, just need to send a client->server ping every x seconds if there haven't been any other messages sent or received in that time. The server can ignore the ping, the point would be for the client to attempt a send that will help it identify a broken connection. |
…ane mode) Situation before #230: Clients maintain keep-alive, sending pings to server. On sudden conn break (e.g. airplane mode), clients would know about the break but the server wouldn't Situation after #230: Server maintains keep-alive, sending pings to clients. On sudden conn break (e.g. airplane mode), server would know about the break but clients wouldn't. As of this commit: Server and clients each maintain a keep-alive[1]. I.e. each side will attempt to ping if it hasn't heard from the other side in a prescribed window. On sudden conn break, each side will be made aware of the break when its own scheduled window fires and fails to successfully send a ping. [1] Timeouts should be different. In particular, the client may like to choose a much more aggressive window (e.g. 5s) to provide a rapid indicator to users.
Have pushed Haven't had an opportunity to test yet, please let me know if this addresses your issue? Thanks! |
…ane mode) Situation before #230: Clients maintain keep-alive, sending pings to server. On sudden conn break (e.g. airplane mode), clients would know about the break but the server wouldn't Situation after #230: Server maintains keep-alive, sending pings to clients. On sudden conn break (e.g. airplane mode), server would know about the break but clients wouldn't. As of this commit: Server and clients each maintain a keep-alive[1]. I.e. each side will attempt to ping if it hasn't heard from the other side in a prescribed window. On sudden conn break, each side will be made aware of the break when its own scheduled window fires and fails to successfully send a ping. [1] Timeouts should be different. In particular, the client may like to choose a much more aggressive window (e.g. 5s) to provide a rapid indicator to users.
Any update on this? May I close? |
Will assume that this is resolved. |
In response for the request for feedback (#259 (comment)). Here is a report on some tests I've done: Summary:
If the intent of Given the behaviour of Chrome, one way to implement such a bound in sente would be for the client to [Edit: removed some preliminary data, added more rigorous data in a comment below] |
Thanks for the testing, where did you test it? On localhost, or over the internet? The reason I ask is that I could imagine Safari might have different behaviour over the internet than on localhost if it's listening to the OS network adapter. |
@danielcompton I tested over the internet (both deployed to a VPS, and also running in dev on a different machine on the same network). I will do some tests in a few hours where the server's network connection drops (vs. my previous tests, which were all for the client). |
Hey Rafal, thanks a lot for the detailed info! Don't have an opportunity to look into this right away, but will try make it a priority next time I'm doing a batch of open-source work. Any additional tests/details/conclusions you (or others) can put together in the meantime would of course be a huge help! Cheers :-) |
I did some more testing on disconnect-detection with the network being disabled on the server-side and client-side. Here are my results: Time for Client to Notice an Abnormal Client-side Network Disconnect
Time for Client to Notice an Abnormal Server-side Network Disconnect
Comments:
Raw data: [1] https://bugs.chromium.org/p/chromium/issues/detail?id=197841 |
I've updated my post above w/ new data. With the client-side However, the time to detect varies greatly between browsers (and even for the same browser), so, it would be nice for sente users to have a way to optionally set their own, more aggressive and standardized threshold. However, this is a further extension, so, perhaps it deserves its own issue? |
Sorry for the delay handling this, have been swamped lately. Will make this my first priority next time I've got some time to batch work on Sente! |
This should hopefully be addressed by the forthcoming v1.18 release. Will ping when the first public alpha is out, and keep this issue open until there's general consensus that the issue is adequately resolved. Apologies for the long delay on this! |
BEFORE THIS COMMIT Client sends regular ping to server on inactivity. When the connection is broken, this sometimes (but not always) triggers a connection close that will then trigger reconnect. AFTER THIS COMMIT Client sends regular ping to server on inactivity AND EXPECTS REPLY FROM SERVER. If the server doesn't reply within a timeout, explicitly triggers a connection close that will then trigger reconnect.
BEFORE THIS COMMIT Client sends regular ping to server on inactivity. When the connection is broken, this sometimes (but not always) triggers a connection close that will then trigger reconnect. AFTER THIS COMMIT Client sends regular ping to server on inactivity AND EXPECTS REPLY FROM SERVER. If the server doesn't reply within a timeout, explicitly triggers a connection close that will then trigger reconnect.
Think it's safe to now close this. |
I'm having difficulty identifying when the websocket connection is down in Chrome. I've looked through the docs and closed issues (some similarities to #230), but wasn't able to find a solution or insights into this particular issue. I hope to confirm that I'm not overlooking an existing Sente feature/option that could help.
Scenario:
Server deployed on Heroku, client logs in, websocket established/first-open, successfully sending messages back/forth. Manually disable wifi on client, cutting the connection.
Expected behavior (both Safari and Firefox):
Within a few seconds (~2-5) the
chsk-state
updates to reflect that the connection is no longer:open?
. Myadd-watch
onchsk-state
picks up the change and renders a notification to the user. Sente begins trying to reconnect every few seconds (longer and longer pauses between attempts). Once the network connection is back up, Sente reestablishes a websocket on next retry attempt.Unexpected actual behavior (Chrome):
No change to
chsk-state
occurs, at least in the 5 minutes I've let it sit after disabling wifi. No event-msgs or errors/warnings appear to be thrown. Once the network is back up, websocket is reestablished and works, but I haven't been able to find anything to watch/capture to inform the client when it's disconnected.Using latest Chrome
Version 52.0.2743.116 (64-bit)
on OSX El Capitan 10.11.6Notes:
After researching, it seems this may be due to Chrome not throwing an "onClose" event when the connection dies, as opposed to Firefox/Safari which do throw that event (which I think Sente captures and reflects in the
chsk-state
)?To get around it, I've considered setting up a ping/pong loop from client to server that fires every few seconds, and assume the connection is down if the client misses a few pongs in a row. But I figured it was worth asking if I overlooked something before building out that workaround, especially since keeping an eye on
chsk-state
works so great in Firefox/Safari.The text was updated successfully, but these errors were encountered: