Inconsistent behavior of `stdio[3]: 'ignore'`
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 272
描述
Version
v21.7.2
Platform
Linux my-laptop 6.5.0-26-generic #26-Ubuntu SMP PREEMPT_DYNAMIC Tue Mar 5 21:19:28 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
child_process
What steps will reproduce the bug?
With print.js:
import {writeSync} from 'node:fs'
const fdNumber = Number(process.argv[2])
writeSync(fdNumber, '.')
With example.js:
import {spawn} from 'node:child_process'
spawn('node', ['./print.js', '1'], {stdio: ['pipe', 'ignore', 'inherit', 'ignore']})
Prints nothing. But:
import {spawn} from 'node:child_process'
spawn('node', ['./print.js', '3'], {stdio: ['pipe', 'ignore', 'inherit', 'ignore']})
Prints the following:
node:fs:933
handleErrorFromBinding(ctx);
^
Error: EINVAL: invalid argument, write
at writeSync (node:fs:933:3)
at file:///home/ether/Desktop/print.js:4:1
at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:120:12) {
errno: -22,
syscall: 'write',
code: 'EINVAL'
}
Node.js v21.7.2
How often does it reproduce? Is there a required condition?
No.
What is the expected behavior? Why is that the expected behavior?
ignore should behave consistently regardless of the same descriptor.
What do you see instead?
ignore's behavior differs between stdio[1] and stdio[3].
Additional information
I understand the reason might be that child processes should always have a stdin/stdout/stderr even when ignored, while this does not apply to other file descriptors. So stdio[3]: 'ignore' probably results in no file descriptor being created, as opposed to stdio[1]: 'ignore'.
On one hand, the current behavior is more efficient, as it does not waste creating a file descriptor that's not going to be used.
On the other hand, this results in inconsistent behavior.
Any change there would be breaking too. So this probably won't be fixed, but I reported it in case this was not intentional.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
运行 print.js 和 example.js 中的复现,以确认 stdio[1] 与 stdio[3] 之间的差异。然后检查 child_process 的实现及相关测试,以确定描述符行为是否是有意设计的。完成的标准是:要么使该行为与测试覆盖保持一致,要么确立其有文档记录且涉及兼容性的理由。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, node.js
- 领域
- backend, operating-systems
- Issue 类型
- 缺陷
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100