You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
TCP sockets have a setKeepAlive function that takes a boolean (for enabled) and an optional number (a number of milliseconds, which will be turned into seconds and then used to set TCP_KEEPIDLE). If you write a program like this:
Tracing this, I found that the code is pretty explicit about this. As you'd expect, we go through different code paths in the two cases. If you call setKeepAlive before being connected, then we set UV_TCP_KEEPALIVE on the libuv handle and apply it once we have an fd, but we always apply it with a delay of 60 seconds instead of whatever the user passed in: https://github.com/joyent/node/blob/v0.12.2-release/deps/uv/src/unix/stream.c#L389-L391
@davepacheco Thank you very much for the detailed bug report!
I would suggest fixing that in master since the behavior change could break a significant number of users, thus adding to the 0.13.1 milestone. @joyent/node-coreteam @davepacheco Thoughts?
TCP sockets have a setKeepAlive function that takes a boolean (for enabled) and an optional number (a number of milliseconds, which will be turned into seconds and then used to set TCP_KEEPIDLE). If you write a program like this:
then this behaves as you'd expect. I'm testing this by setting up a server on the remote IP using:
and using this command to snoop traffic:
With the above program, snoop shows (output trimmed for clarity):
That's the initial connection, followed by two rounds of keep-alive separated by 10 seconds each.
But if you change the program so that you call setKeepAlive right after calling connect(), but before the 'connected' event:
and run that, then snoop shows that we send keepalive packets every 60 seconds instead of every 10:
Tracing this, I found that the code is pretty explicit about this. As you'd expect, we go through different code paths in the two cases. If you call setKeepAlive before being connected, then we set UV_TCP_KEEPALIVE on the libuv handle and apply it once we have an fd, but we always apply it with a delay of 60 seconds instead of whatever the user passed in:
https://github.com/joyent/node/blob/v0.12.2-release/deps/uv/src/unix/stream.c#L389-L391
That's because we never save the delay that the user passed in:
https://github.com/joyent/node/blob/v0.12.2-release/deps/uv/src/unix/tcp.c#L297-L310
Anyway, the net result of this is that the user asked for a delay of 10s, but Node silently picked a completely different value.
The text was updated successfully, but these errors were encountered: