Skip to content

child_process: check for closed pipes after creating socket#38716

Open
seangoedecke wants to merge 1 commit intonodejs:mainfrom
seangoedecke:sgoedecke/handle-child-process-stdin-close
Open

child_process: check for closed pipes after creating socket#38716
seangoedecke wants to merge 1 commit intonodejs:mainfrom
seangoedecke:sgoedecke/handle-child-process-stdin-close

Conversation

@seangoedecke
Copy link

After the socket is created, this PR now triggers an empty read to make sure we catch stdio events like closing the stdin file descriptor. Otherwise those events will go undetected until the next stream write.

Fixes: #25131

After the socket is created, we trigger an empty read to make sure we
catch stdio events like closing the stdin file descriptor. Otherwise
those events will go undetected until the next stream write.

Fixes: nodejs#25131
@github-actions github-actions bot added child_process Issues and PRs related to the child_process subsystem. needs-ci PRs that need a full CI run. labels May 18, 2021
@aduh95
Copy link
Contributor

aduh95 commented Sep 20, 2023

Hey @seangoedecke, sorry your PR was not reviewed for so long! Any chance you would be able to rebase on top of main to get it back to a state where it can land? Or let me know if you prefer I do it for you.

stream.handle : null, i > 0);

// Trigger an empty read to check for a closed pipe
// or the close event will go undetected until next write
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// or the close event will go undetected until next write
// or the close event will go undetected until next write.

const fs = require('fs');

if (process.argv[2] === 'child') {
fs.closeSync(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to use closeSync(0) rather than process.stdin.end()? If so, can you add a comment?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as I understand the closeSync(0) is used because it needs to immediately close the standard input stream synchronously, however it's really good question why we cannot asynchronous handling of the end of the input stream?

@Tseian
Copy link
Contributor

Tseian commented Mar 19, 2026

I build a debug out node from this PR to test the repoduced example, it does not resolve the problem.
As far as I know. Not trigger cp.stdin close event is correct. It is a bug that the close event was triggered.

So can this PR be closed?

@aduh95 aduh95 added the stalled Issues and PRs that are stalled. label Mar 19, 2026
@github-actions
Copy link
Contributor

This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open.

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. stalled Issues and PRs that are stalled.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

regression: child_process stdin pipe close event not emitted

4 participants