Skip to content

child_process: watch child_process stdin pipe peer close event#62353

Open
Tseian wants to merge 2 commits intonodejs:mainfrom
Tseian:main
Open

child_process: watch child_process stdin pipe peer close event#62353
Tseian wants to merge 2 commits intonodejs:mainfrom
Tseian:main

Conversation

@Tseian
Copy link
Contributor

@Tseian Tseian commented Mar 20, 2026

Issue

#25131

Description

Watch pipe peer close(EOF/HUP) event, only support for unix. Once the event is detected, a JS callback is triggered to execute, which in turn triggers a method to destroy the socket. Eventually child_process.stdin.on('close') will be triggered.

Before

child_process.stdin.on('close') will not be triggered if the readable end of the pipe has been closed.

After

child_process.stdin.on('close') will be triggered if the readable end of the pipe has been closed.

Changes

Test

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Mar 20, 2026
@Tseian Tseian changed the title child-process: watch pipe peer close event WIP child-process: watch pipe peer close event Mar 20, 2026
@Tseian Tseian force-pushed the main branch 3 times, most recently from 071fa18 to 4cedb07 Compare March 21, 2026 06:11
@codecov
Copy link

codecov bot commented Mar 21, 2026

Codecov Report

❌ Patch coverage is 72.72727% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.68%. Comparing base (69fdff9) to head (dc21154).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
src/pipe_wrap.cc 69.64% 5 Missing and 12 partials ⚠️
lib/internal/child_process.js 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62353      +/-   ##
==========================================
+ Coverage   89.67%   89.68%   +0.01%     
==========================================
  Files         676      676              
  Lines      206693   206772      +79     
  Branches    39576    39599      +23     
==========================================
+ Hits       185346   185453     +107     
+ Misses      13482    13445      -37     
- Partials     7865     7874       +9     
Files with missing lines Coverage Δ
src/pipe_wrap.h 100.00% <ø> (ø)
lib/internal/child_process.js 94.69% <90.00%> (-0.24%) ⬇️
src/pipe_wrap.cc 77.52% <69.64%> (-3.78%) ⬇️

... and 37 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Tseian Tseian force-pushed the main branch 2 times, most recently from 0ae2360 to 09463c0 Compare March 21, 2026 08:21
@Tseian Tseian changed the title WIP child-process: watch pipe peer close event child-process: watch pipe peer close event Mar 21, 2026
@Tseian Tseian force-pushed the main branch 2 times, most recently from 9e25a20 to 78acd67 Compare March 21, 2026 14:26
@Tseian Tseian changed the title child-process: watch pipe peer close event child-process: watch child_process stdin pipe peer close event Mar 21, 2026
@Tseian Tseian force-pushed the main branch 3 times, most recently from e704d96 to 8cc7608 Compare March 22, 2026 01:43
@Tseian Tseian changed the title child-process: watch child_process stdin pipe peer close event child_process: watch child_process stdin pipe peer close event Mar 22, 2026
@Tseian
Copy link
Contributor Author

Tseian commented Mar 22, 2026

@nodejs-github-bot retest

@Tseian
Copy link
Contributor Author

Tseian commented Mar 23, 2026

@jasnell @ronag @jbunton-atlassian Hi everyone, Could you please have a code review for this PR?

args.GetReturnValue().Set(err);
}

void PipeWrap::WatchPeerClose(const FunctionCallbackInfo<Value>& args) {
Copy link
Member

@jasnell jasnell Mar 23, 2026

Choose a reason for hiding this comment

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

Rather than exposing two functions, can this expose a single function with a single bool argument? e.g. watchPeerClose(true, callback) / watchPeerClose(false)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, Got it. I'll commit it soon.

wrap->peer_close_watching_ = false;
wrap->peer_close_cb_.Reset();
}
args.GetReturnValue().Set(err);
Copy link
Member

Choose a reason for hiding this comment

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

Is the err return value actually used on the JavaScript side? If it is, I'm not seeing where.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, it's not currently used in the JS side. Do you mean that if it's not used in the JS side, we shouldn't return a value?

I saw that Bind and Connect both return values, and I assumed this was a convention.

src/pipe_wrap.cc Outdated
// Stop listening and release the JS callback to prevent memory leaks.
wrap->peer_close_watching_ = false;
wrap->peer_close_cb_.Reset();
args.GetReturnValue().Set(uv_read_stop(wrap->stream()));
Copy link
Member

Choose a reason for hiding this comment

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

Likewise here, the return value does not appear to be used at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants