Skip to content

child_process: emit 'close' after explicit disconnect() - #65665

Open
3zrv wants to merge 1 commit into
nodejs:mainfrom
3zrv:fix-child-process-disconnect-close
Open

child_process: emit 'close' after explicit disconnect()#65665
3zrv wants to merge 1 commit into
nodejs:mainfrom
3zrv:fix-child-process-disconnect-close

Conversation

@3zrv

@3zrv 3zrv commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

An explicit subprocess.disconnect() closed the IPC channel without counting it towards the subprocess 'close' event, so 'close' was never emitted once the child exited. Route every channel teardown through the same finish() so the accounting happens where the channel is closed, and drop the handle queue on EOF so the disconnect is not postponed forever.

Fixes: #19433 #65646
Refs: #19566

After the parent calls subprocess.disconnect(), the subprocess never emits 'close' once the child exits, even though 'exit' fires and all stdio pipes close. The IPC channel had two teardown paths: the EOF path did maybeClose(target), but the explicit-disconnect path (_disconnect()finish()) only closed the channel and emitted 'disconnect', so the channel counted in _closesNeeded was never matched (_closesGot stuck at 2 of 3).

This makes finish() the single place a channel is torn down, close the handle and emit 'disconnect', then maybeClose() and routes the EOF path through it.

An explicit subprocess.disconnect() closed the IPC channel without
counting it towards the subprocess 'close' event, so 'close' was never
emitted once the child exited. Route every channel teardown through the
same finish() so the accounting happens where the channel is closed, and
drop the handle queue on EOF so the disconnect is not postponed forever.

Fixes: nodejs#19433
Refs: nodejs#19566
Signed-off-by: Mohamed Sayed <k@3zrv.com>
@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 Aug 30, 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.

child_process: 'close' not emitted after .disconnect() in parent process

2 participants