nodejs / nodejs/node

`for await (const c of process.stdin)` does not accept EOF in Windows

オープン
#61,397 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

Version

v24.13.0

Platform
Microsoft Windows NT 10.0.26200.0 x64
Subsystem

No response

What steps will reproduce the bug?
  1. Run node -e "for await (const c of process.stdin) console.log(c)"
  2. [f] [o] [o] [Enter]
  3. [Ctrl] + [Z] or [Ctrl] + [D] (= EOF)
  4. [Enter]
How often does it reproduce? Is there a required condition?

Always

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

In Ubuntu and Alma Node successfully stop reading by Ctrl + D:

$ node -e "for await (const c of process.stdin) console.log(c)"
foo
<Buffer 66 6f 6f 0a>
What do you see instead?

Node will never stop reading in spite of [Ctrl] + [Z] or [Ctrl] + [D]:

PS> node -e "for await (const c of process.stdin) console.log(c)"
foo
<Buffer 66 6f 6f 0d 0a>
^Z
<Buffer 1a 0d 0a>
^D
<Buffer 04 0d 0a>

I had to end up with killing the process by Ctrl + C.

Additional information

I usually use Proto to manage Node versions, but it was able to be reproduced in the portable version in the official zipball:

PS> .\Downloads\node-v24.13.0-win-x64\node -e "for await (const c of process.stdin) console.log(c)"
foo
<Buffer 66 6f 6f 0d 0a>
^Z
<Buffer 1a 0d 0a>
^D
<Buffer 04 0d 0a>

PS> echo $?
False

(ended up with Ctrl + C)

Workaround: insert if ((c[0] === 4 || c[0] === 0x1a) && c.length === 1 + EOL.length && c.toString("latin1", c.length - EOL.length) === EOL) break; (import { EOL } from "node:os")

If this bug did not exist, you would be able to retrieve the entire multiline text from stdin by (await Array.fromAsync(process.stdin)).join("") in all platforms.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、報告されている node -e "for await (const c of process.stdin) ..." コマンドを Windows で実行して問題を再現し、process.stdin の非同期反復のエントリーポイントを追跡します。Ctrl+Z または Ctrl+D が EOF として認識され、ループが終了し、その動作が Windows のリグレッションテストでカバーされれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, node.js
領域
cli, operating-systems
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。