Skip to content

net: warn on keep-alive delays truncated to zero - #65528

Open
zeexzeex wants to merge 1 commit into
nodejs:mainfrom
zeexzeex:net-keepalive-warning
Open

net: warn on keep-alive delays truncated to zero#65528
zeexzeex wants to merge 1 commit into
nodejs:mainfrom
zeexzeex:net-keepalive-warning

Conversation

@zeexzeex

Copy link
Copy Markdown

socket.setKeepAlive() takes its delays in milliseconds, but the underlying
socket options are configured in whole seconds. A positive value below 1000
rounds down to 0, which leaves the system default in place instead of
applying the requested timing:

socket.setKeepAlive(true, 400); // TCP_KEEPIDLE is left unchanged

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 and
rejects a delay below 1. This makes the truncation visible instead.

Changes

  • Emit a KeepAliveWarning when a positive initialDelay or interval is
    truncated to zero. 0 keeps its documented meaning of leaving the current
    setting unchanged and does not warn, and nothing is reported when keep-alive
    is being disabled.
  • Document the result of the truncation in net.md. The rounding itself was
    already described; what was missing was that a value below 1000 ends up not
    being applied at all.
  • Fix two existing tests that passed values below 1000 ms which did not match
    what their comments described.

Refs: #57712

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem. labels Aug 25, 2026
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.03%. Comparing base (4b5e86c) to head (cc29daa).
⚠️ Report is 195 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65528      +/-   ##
==========================================
- Coverage   90.14%   90.03%   -0.11%     
==========================================
  Files         751      769      +18     
  Lines      253679   261335    +7656     
  Branches    47789    49625    +1836     
==========================================
+ Hits       228671   235301    +6630     
- Misses      16264    17051     +787     
- Partials     8744     8983     +239     
Files with missing lines Coverage Δ
lib/net.js 94.59% <100.00%> (+0.03%) ⬆️

... and 176 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Emit a KeepAliveWarning when a positive initialDelay or interval is
truncated to zero, and document the behaviour. A value of 0 keeps its
documented meaning of leaving the current setting unchanged and does
not warn.

Two existing tests passed values below 1000 ms that did not match what
their comments described; they now use 1000 ms.

Refs: nodejs#57712
Signed-off-by: Avocado <[email protected]>
@zeexzeex
zeexzeex force-pushed the net-keepalive-warning branch from 1e4c167 to cc29daa Compare September 4, 2026 01:25
@mcollina

mcollina commented Sep 4, 2026

Copy link
Copy Markdown
Member

I don't think we should be landing a warning for this. I think we should be throwing an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants