Closed

Description
- Version: v10.10.0
- Platform: Windows x64
parent.js
require('child_process').spawn('node', ['child.js'], {
stdio: 'inherit',
});
child.js
const doNothing = () => {};
process.stdin.on('data', doNothing);
require('child_process').spawn('node', ['-v']).on('exit', () => {
process.stdin.unref();
console.log('After printing this, the process should exit');
});
Run with node parent.js
Results
Linux: The process terminates by itself
Mac: The process terminates by itself
Windows: The process keeps running until Enter is pressed
This strange behavior seems to break some npm modules.
Other details
Adding process.stdin.removeListener('data', doNothing)
or process.stdin.removeAllListeners('data')
before unref
doesn't make any difference.
When enter is pressed, it doesn't trigger data
callback, just terminates the process.
Edit
Simplified code:
// parent.js
process.stdin.on('data', () => {});
setTimeout(() => {
process.stdin.unref();
console.log('After printing this, the process should exit');
});
Here we don't have a child process. Run with node parent.js
Results on windows
50% of times - the process exits
50% of times - the process keeps running