net: warn on keep-alive delays truncated to zero - #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.21% +0.06%
==========================================
Files 751 771 +20
Lines 253679 264651 +10972
Branches 47789 50241 +2452
==========================================
+ Hits 228671 238746 +10075
- Misses 16264 16910 +646
- Partials 8744 8995 +251
🚀 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
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 indicates that the value had no effect. There is no exception, no
warning, and the return value is the socket either way, so the caller has 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 below 1. This makes the truncation visible instead.
Changes
KeepAliveWarningwhen a positiveinitialDelayorintervalistruncated to zero.
0keeps its documented meaning of leaving the currentsetting unchanged and does not warn, and nothing is reported when keep-alive
is being disabled.
net.md. The rounding itself wasalready described; what was missing was that a value below
1000ends up notbeing applied at all.
1000ms which did not matchwhat their comments described.
Refs: #57712