Inconsistent behavior of `stdio[3]: 'ignore'`
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 122k
- フォーク
- 37.3k
- 平均マージ
- 4日 2時間
- マージ済み PR(30日)
- 283
説明
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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
print.js と example.js から再現手順を実行して、stdio[1] と stdio[3] の違いを確認します。次に、child_process の実装と関連するテストを調べ、ディスクリプタの挙動が意図的なものかどうかを判断します。挙動がテストカバレッジと一貫するようにされるか、または互換性に関わるその根拠が文書化された形で確立されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, node.js
- 領域
- backend, operating-systems
- issue の種類
- バグ
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100