Skip to content

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

Description

@laino
  • Version: v9.8.0
  • Platform: Linux 64bit
  • Subsystem: child_process

When calling child.disconnect() from a parent process (not in cluster mode), the child process object does not emit a close event after the exit event.

If however the child process itself calls process.disconnect() it works as expected.

Example:

// parent.js
const child_process = require('child_process');

const child = child_process.fork('./child.js', {
    stdio: ['pipe', 'pipe', 'pipe', 'ipc']
});

setTimeout(() => {
    child.disconnect();
}, 1000);

child.on('exit', () => {
    console.log('exit');
});

child.on('close', () => {
    console.log('close');
});

child.stderr.pipe(process.stderr);
child.stdout.pipe(process.stdout);
// child.js
process.on('disconnect', () => {
    console.log('cya');
});

Output:

cya
exit

Expected Output:

cya
exit
close

Activity

  1. added
    child_processIssues and PRs related to the child_process subsystem.
    on Mar 18, 2018
  2. ryzokuken commented on Jun 7, 2018

    @ryzokuken
    Contributor

    ping @laino

  3. added
    help wantedIssues that need assistance from volunteers or PRs that need help to proceed.
    on Jun 26, 2020
  4. github-actions commented on Jun 27, 2026

    @github-actions
    Contributor

    This issue has been marked as stale due to 210 days of inactivity.
    It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

  5. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jun 27, 2026
  6. github-actions commented on Jul 28, 2026

    @github-actions
    Contributor

    This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
    If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions