-
Notifications
You must be signed in to change notification settings - Fork 7.3k
setKeepAlive silently ignores invalid values #21080
Comments
@davepacheco I think you may have solved a bug that I've been trying to track down for a long time. Could you share what platform you're on? I'm trying to figure out what the minimum keep alive time is for the systems I'm deploying to but am not finding much useful information. |
I'm on illumos (SmartOS, specifically). There's some information on finding the value on various systems at http://www.gnugk.org/keepalive.html. Hope that helps! |
It looks like libuv returns a negative number when
Maybe it should just return a true/false? |
I'd suggest treating this as a programming error and throwing an exception that should generally not be handled (except maybe to print a friendlier error message). We could also have emit an error on the socket so that programs could treat it as an operational error. |
Emitting an EDIT: Actually, throwing seems like it would make more sense, since most error return values from |
FYI...
|
@saquibkhan Good catch, thanks! 👍 |
socket.setKeepAlive now throws an error if the operation fails. For example setting the keep alive time too small, or calling the function on a closed socket. Fixes nodejs#21080
While testing #21079, I also discovered that TCP sockets' setKeepAlive() function silently ignores invalid values. I tried passing 5000ms for the delay, which gets translated to 5s. On my system, the minimum is 10s, and the setsockopt returns with EINVAL, but Node neither throws an exception nor emits an Error on the socket. Here's the test program:
and here's the output while tracing setsockopt():
(On this system, 0x22 is TCP_KEEPIDLE. I checked that the value being passed in was "5", and that's less than the minimum allowed on this system.)
The text was updated successfully, but these errors were encountered: