child_process: emit close after parent disconnect - #66069
Closed
rasadregmi wants to merge 1 commit into
Closed
rasadregmi wants to merge 1 commit into
rasadregmi wants to merge 1 commit into
Conversation
Contributor
|
Welcome to Node.js, and thank you for your first contribution! Before review, please take a moment to read:
Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal. |
The 'close' event was not emitted when the parent called subprocess disconnect() before the channel reached EOF. _disconnect()'s finish() closed the channel and emitted 'disconnect' but never accounted for the channel closure with maybeClose(), so _closesGot never reached _closesNeeded and the 'close' event was lost. Account for the channel closure in finish() and defer that accounting to the EOF handler only when _disconnect() was deferred by a pending handle queue, to avoid double counting. Fixes: nodejs#65646 Signed-off-by: Rasad Regmi <regmirasad53@gmail.com>
rasadregmi
force-pushed
the
fix/child-process-close
branch
from
September 16, 2026 16:11
f67d655 to
a6168c1
Compare
Author
|
Closing in favor of #65665 which addresses this more thoroughly, including handle queue cleanup. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the parent calls
subprocess.disconnect()before the IPC channel reaches EOF, thecloseevent is never emitted after the child exits.disconnect,exit, and stdiocloseall fire, so code waiting onclosehangs even though the child process and its pipes are gone.The IPC channel slot is normally accounted for by
maybeClose(), called from the channel's EOF handler, but that path is never reached when the parent closes the channel itself:_disconnect()'sfinish()closed the channel and emitted'disconnect'without callingmaybeClose(), so_closesGotnever reached_closesNeededand thecloseevent was lost.This change counts the channel closure in
finish()after emitting'disconnect'. The EOF handler now performs that accounting only when_disconnect()was deferred by a pending handle queue (the case where the child exits before the queue drains), so each channel closure is still counted exactly once and the EOF path plus exit-before-close ordering are preserved.Regression test
test/parallel/test-child-process-disconnect-close.jsasserts thatcloseis emitted exactly once with(0, null)after a parent-initiateddisconnect(); it fails on current main and passes with this change. The fulltest/parallel/test-child-process-*.jssuite passes locally.Fixes: #65646