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

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 <ujubongbong@gmail.com>
@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
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.

2 participants