net: setKeepAlive() ignores the error returned by the handle
維護者通常 1 天內回覆
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 48/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- cpp, javascript, nodejs
- 領域
- networking
研究方向
從 src/tcp_wrap.cc 中的 socket.setKeepAlive() 路徑和 TCPWrap::SetKeepAlive 開始,然後重現 issue 中的負延遲情況。將其處理方式與 setTypeOfService() 進行比較,並調查 macOS 和其他系統上所指出的平台行為。當底層失敗不再被靜默丟棄,並使用團隊核准的錯誤行為時,即視為完成。
由索引模型根據 Issue 內容生成。
描述
Version
v27.0.0-pre (main)
Platform
Darwin 25.4.0 arm64
Subsystem
net
What steps will reproduce the bug?
const net = require('net');
const server = net.createServer().listen(0, () => {
const socket = net.connect(server.address().port, () => {
// Looks like it succeeded
const returned = socket.setKeepAlive(true, -5000);
console.log('returns socket:', returned === socket);
// The handle actually returned EINVAL
const err = socket._handle.setKeepAlive(true, -5, 1, 10);
console.log('handle returns:', err);
socket.destroy();
server.close();
});
});
Output:
returns socket: true
handle returns: -22
How often does it reproduce? Is there a required condition?
Every time, for any value the platform rejects.
What is the expected behavior? Why is that the expected behavior?
socket.setKeepAlive() should not report success when the underlying
operation failed. setTypeOfService(), right next to it in the same file,
already does this:
const err = this._handle.setTypeOfService(tos);
if (err && !isWindows) {
throw new ErrnoException(err, 'setTypeOfService');
}
What do you see instead?
setKeepAlive() discards the return value of the handle call:
this._handle.setKeepAlive(enable, initialDelay, interval, count);
TCPWrap::SetKeepAlive does propagate the error to JS
(args.GetReturnValue().Set(err) in src/tcp_wrap.cc), and
uv_tcp_keepalive_ex() returns UV_EINVAL for a negative delay, so the
information is available. It is simply dropped.
The caller has no way to tell: the return value is the socket either way,
and no error is thrown or emitted.
Additional information
Found while working on #57712 / #65528, which adds a warning for delays
below 1000 ms that are truncated to 0. That change is about values which
are silently reduced; this one is about an error which is silently
discarded, so it seemed better to report it separately.
I have not checked how a value above the platform limit behaves on other
systems. On macOS setKeepAlive(true, 40000000) (40000 s) is accepted by
the handle, so any range check would need per-platform investigation first.
I am happy to open a PR if the direction is agreed. Whether a failure
should throw, like setTypeOfService(), or only emit a warning is a
decision I would rather leave to the team, since throwing would be a
breaking change.
- 主要語言
- JavaScript
- 星號
- 122k
- 分支
- 38.4k
- 平均合併
- 3 天 23 小時
- 30 天內合併 PR
- 274
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
nodejs/node 的其他 Issue
-
build / doc: missing platform and toolchain info for `linux-x64-musl`可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉alpine build doc
難度 2/5 1-3 小時 新手友好度 75/100
維護者通常 1 天內回覆
-
[Docs] `process.loadEnvFile()` does not document behaviour when variables already exist可能已有人在做 @Sepandard 於 9 天前認領。 未關閉doc
難度 1/5 1 小時以內 新手友好度 90/100
維護者通常 1 天內回覆
-
Stream.prototype.forEach will block in first promise in queue before read more chunk可能已有人在做 @mmustafasenoglu 於 10 天前認領。 未關閉doc
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆
-
build
難度 1/5 1 小時以內 新手友好度 88/100
維護者通常 1 天內回覆
-
`TextEncoder.encodeInto()` underfills the destination for some non-ASCII text可能已有人在做 @XadillaX 於 23 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 84/100
nodejs/node#65994 · 2 則留言 · 2 個 reaction ·
維護者通常 1 天內回覆
相似的 Issue
-
automated issue report
難度 2/5 1-3 小時 新手友好度 62/100
lirantal/discoprint#36 ·
維護者通常 1 天內回覆
-
accepting PR Content:HTML
難度 1/5 1 小時以內 新手友好度 88/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
txn2/mcp-data-platform#2030 ·
維護者通常 1 天內回覆
-
ci hacktoberfest help wanted size/small type/bug type/docs type/enhancement up-for-grabs
難度 2/5 1-3 小時 新手友好度 88/100
Redo-San/RedoSan-Authenticity#527 ·
維護者通常 1 天內回覆