net: reject keep-alive delays that cannot be applied - #65528
Conversation
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65528 +/- ##
==========================================
+ Coverage 90.14% 90.30% +0.16%
==========================================
Files 751 771 +20
Lines 253679 267033 +13354
Branches 47789 51445 +3656
==========================================
+ Hits 228671 241157 +12486
- Misses 16264 16902 +638
- Partials 8744 8974 +230
🚀 New features to boost your workflow:
|
1e4c167 to
cc29daa
Compare
|
I don't think we should be landing a warning for this. I think we should be throwing an error. |
cc29daa to
e36ca60
Compare
|
@mcollina Agreed, switched to throwing. This surfaced Five tests also pass Two questions: does this need |
The keep-alive delays are given in milliseconds but the underlying socket options are configured in whole seconds, so a positive value below 1000 ms rounds down to 0. That leaves the system default in place instead of applying the requested timing, and there is nothing to indicate that the value had no effect. uv_tcp_keepalive() already rejects a delay outside [1, 32767] seconds, so the value is treated as invalid one layer down. Throw ERR_OUT_OF_RANGE for a positive initialDelay or interval that cannot be applied as requested, covering both the truncation to zero and the upper bound the socket options can carry. A non-positive value keeps its documented meaning of leaving the current setting unchanged, and Infinity is accepted as "no timeout" by callers such as Agent. Three existing tests passed delays that were silently ignored; test-async-hooks-http-parser-destroy had never configured keep-alive at all despite asking for it. Refs: nodejs#57712 Signed-off-by: Avocado <ujubongbong@gmail.com>
e36ca60 to
6222f2f
Compare
|
ptal @nodejs/tsc |
1 similar comment
|
ptal @nodejs/tsc |
|
@zeexzeex please update the PR title and description |
socket.setKeepAlive()takes its delays in milliseconds, but the underlyingsocket options are configured in whole seconds. A positive value below
1000rounds down to
0, which leaves the system default in place instead ofapplying the requested timing:
Nothing indicated that the value had no effect. There was no exception, no
warning, and the return value was the socket either way, so the caller had no
way to tell that keep-alive was not configured as asked.
Sub-second timings cannot be supported:
uv_tcp_keepalive()takes seconds andrejects a delay outside
[1, 32767]. This change rejects a delay that cannotbe applied as requested, instead of silently altering it.
Changes
ERR_OUT_OF_RANGEwhen a positiveinitialDelayorintervalwouldtruncate to zero or exceed the
32767second socket-option limit.Non-positive values keep their documented meaning of leaving the current
setting unchanged.
Infinity(used byAgentto mean "no timeout") is leftalone for the same reason.
net.md.1000ms which never actuallyconfigured keep-alive.
http.Agentreaches this path viakeepAliveMsecs, so a value below1000now throws instead of being ignored.
Refs: #57712