nodejs / nodejs/node

setkeepalive < 1000 silently ignored

未关闭
#57,712 9 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

doc net
主要语言
JavaScript
星标
122k
派生
37.3k
平均合并
4 天 2 小时
30 天内合并 PR
283

描述

Version

22.14.0

Platform
N/A
Subsystem

No response

What steps will reproduce the bug?

Create a TCP socket and call socket.setKeepAlive(true, 400).

How often does it reproduce? Is there a required condition?

Any keepalive less than 1 second.

What is the expected behavior? Why is that the expected behavior?

This should send keepalive packets every 400 ms.

The documentation says as much:

keepAliveInitialDelay {number} If set to a positive number, it sets the
initial delay before the first keepalive probe is sent on an idle socket.
Default: 0.

What do you see instead?

The code truncates to the nearest 1000ms, so the socket doesn't send keepalive packets and no error is issued.

Additional information

It seems this parameter is even broken in the tests.

https://github.com/nodejs/node/blob/3db54912fa2e4a696d4e2ec27dfb2aeecfc65191/test/parallel/test-net-keepalive.js#L42
https://github.com/nodejs/node/blob/3db54912fa2e4a696d4e2ec27dfb2aeecfc65191/test/parallel/test-net-persistent-keepalive.js#L30

Ideally, the keepalive interval would be respected in milliseconds. Assuming that's infeasible,

  1. a runtime warning should be issued if setKeepAlive is given a value <1000.
  2. the documentation should be updated to reflect that, even though the value is given in milliseconds, it will only be respected to the second.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

Start at the socket.setKeepAlive(true, 400) entry point and inspect the behavior covered by test/parallel/test-net-keepalive.js and test/parallel/test-net-persistent-keepalive.js. Determine whether subsecond delays should be supported or rejected, then update the relevant tests and documentation so the chosen behavior is explicit and verified.

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, node.js
领域
networking
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
64/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。