Skip to content

child_process: emit close on parent stdin when child closes fd 0#62945

Closed
maruthang wants to merge 1 commit intonodejs:mainfrom
maruthang:fix-25131-child-stdin-close
Closed

child_process: emit close on parent stdin when child closes fd 0#62945
maruthang wants to merge 1 commit intonodejs:mainfrom
maruthang:fix-25131-child-stdin-close

Conversation

@maruthang
Copy link
Copy Markdown

Since PR #18701 the parent's child.stdin Socket stopped emitting
close because the Socket is constructed with readable: false,
which suppresses the constructor's read(0) call. Without the libuv
read loop, the kernel's EOF/HUP signal (raised when the child
closes its end of the stdin pipe) is never observed, so the close
cascade never runs.

Install a minimal onread callback on the underlying Pipe handle
and call pipe.readStart() so EOF is delivered. The callback only
acts on UV_EOF and calls socket.destroySoon() so pending writes
drain. Unexpected inbound data is absorbed via readStop() so the
read side-channel is not resurrected.

Fixes: #25131


Note: I was unable to run the test suite locally on Linux/macOS (no built out/Release/node on this Windows host; named-pipe EOF semantics on Windows differ, hence the test guard). The fix matches the reporter's documented workaround and Tseian's analysis on the issue thread. Looking forward to CI verification on Linux/macOS runners.

Since PR nodejs#18701 the parent's child.stdin Socket stopped emitting
`close` because the Socket is constructed with readable: false,
which suppresses the constructor's read(0) call. Without the libuv
read loop, the kernel's EOF/HUP signal (raised when the child
closes its end of the stdin pipe) is never observed, so the close
cascade never runs.

Install a minimal onread callback on the underlying Pipe handle
and call pipe.readStart() so EOF is delivered. The callback only
acts on UV_EOF and calls socket.destroySoon() so pending writes
drain. Unexpected inbound data is absorbed via readStop() so the
read side-channel is not resurrected.

Fixes: nodejs#25131
Signed-off-by: Maruthan G <[email protected]>
@nodejs-github-bot nodejs-github-bot added child_process Issues and PRs related to the child_process subsystem. needs-ci PRs that need a full CI run. labels Apr 25, 2026
@addaleax
Copy link
Copy Markdown
Member

Still think the approach discussed in #62353 is the way to go here

@maruthang
Copy link
Copy Markdown
Author

Closing in favor of #62353 per @addaleax — the C++ pipe-wrap peer-close approach taken there is the right shape, rather than driving EOF detection from JS via pipe.readStart() + onread. Thanks for the steer.

@maruthang maruthang closed this Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

child_process Issues and PRs related to the child_process subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

regression: child_process stdin pipe close event not emitted

3 participants