nodejs/node

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

Open

#19,433 建立於 2018年3月18日

在 GitHub 查看
 (2 留言) (1 反應) (0 負責人)JavaScript (35,535 fork)batch import
child_processhelp wantedstale

倉庫指標

Star
 (117,218 star)
PR 合併指標
 (平均合併 18天 17小時) (30 天內合併 219 個 PR)

描述

  • 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

貢獻者指南