-
Notifications
You must be signed in to change notification settings - Fork 171
fixed wrong pingInterval and pingTimeout #39
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
Conversation
|
I have commented all fixes with // FIX. Just remove these after you agree with the change. I manually picked code changes into this repo, if anything shouldn't work as supposed, have a look at my fork please. |
|
fixes #38 |
|
Can you explain how is the original code wrong? |
|
It has been a long time since I posted this and I'll do my best to recount this error-free. What I think to remember is that the total timeout was I believe default values are set in a way, where |
|
Just to make the things clear, ping/pong and heartbeat work the same with JS client.
Maybe this is the intended behavior, like waiting for sendPing (pingInterval) and timeout (pingTimeout) after that.
Basically, ping/pong is for detecting inactive client/server including network froze. So I think we don't need to think about second ping. |
|
Timeout should be an absolute value after which something times out. I don't see any reason why the heartbeat interval should be added to that value. If the reference implementation does it like that, then they probably do it wrong. Also the second ping is necessary, otherwise the timeout could be reduced to slightly above 35 seconds. There would be no reason for waiting that long before reconnecting. @nkzawa I do understand that you want to stick to the reference implementation, but more important is that it works. And you can see from the many complaints about disconnects that it doesn't. |
|
About the timeout, still not sure, but I agree it might be no reason actually. About the second packet, I'd like to be more careful and discuss for better solutions. For example, can't we just make the reconnection cycle fast with less timeout and interval settings? Or it might be better to retry sending Anyway it would be great if we can fix JS client and server as well. |
I tried that, but to achieve being reconnected within 5 secs would require a pingInterval of 1 sec and connect timeout of 3 sec, which is not feasible.
This won't work because you don't know that the first ping has failed, as long as it hasn't timed out yet. Exactly the reason why I am scheduling consecutive pings without further intervention. But that still wouldn't speed up reconnection, because even with a short connect timeout of 10 secs you would need 2 x 10 secs to realize that something is wrong. I tried a lot of things, like canceling requests from the client and retrying, returning noop from the server after a certain time, sending 2 consecutive pings one after the other, etc. But all solutions I came up with are too expensive and therefore not feasible in production. For the moment I gave up on this. |
|
Main problem also is that we are on Android. And as we know versions up to 4.3 are having network issues. The problem is that the server responds to the ping, while Android receives the response on the network layer but does not bubble it up. At least on ASUS devices this seems to be an issue. socketio/socket.io-client-java#250. So we can't do much on the server-side, either. The server thinks all is good. |
|
Closed due to inactivity, please reopen if needed. |
There were some strange wirings and wrong calculations of pingTimeout which I cleaned up. The sequence is now onPacket -> emitHeartbeat -> setPing -> setHeartbeat (previously onHeartbeat).
Whatever packet is received, it must reset pingInterval AND pingTimeout, but pingInterval must repeat, so it is not possible to set both within the scheduled Runnable within setPing.