Repository navigation
Closed
Labels
child_processIssues and PRs related to the child_process subsystem.Issues and PRs related to the child_process subsystem.windowsIssues and PRs related to the Windows platform.Issues and PRs related to the Windows platform.
Description
Let's consider this example project consisting of 3 files:
// main.js
var spawn = require('child_process').spawn;
var middle = spawn(process.execPath, ['middle.js'], {
'stdio': 'pipe'
});
middle.stdout.on('data', function(data) {
process.stdout.write('stdout from middle: ' + data);
});
middle.stderr.on('data', function(data) {
process.stdout.write('stderr from middle: ' + data);
});
middle.on('close', function(code) {
process.stdout.write('middle process finished with exit code ' + code);
});// middle.js
var spawn = require('child_process').spawn;
var stdin = process.stdin;
console.log('middle: isatty(stdin)=' +require('tty').isatty(stdin));
spawn(process.execPath, ['child.js'], {
'stdio': [process.stdin, process.stdout, process.stderr]
});// child.js
console.log('child: accessing process.stdin');
console.log('child: done successfully ' + process.stdin);Running node main.js in cmd.exe should normally output these lines and exit
stdout from middle: middle: isatty(stdin)=false
stdout from middle: child: accessing process.stdin
stdout from middle: child: done successfully [object Object]
middle process finished with exit code 0
However, from time to time it outputs only two first lines and hangs:
stdout from middle: middle: isatty(stdin)=false
stdout from middle: child: accessing process.stdin
The hanging is caused by accessing process.stdin in child.js. Please note it works fine if process.stdin is replaced with 'pipe' here:
// middle.js
...
spawn(process.execPath, ['child.js'], {
'stdio': ['pipe', process.stdout, process.stderr]
});Node.js v7.4.0
OS Windows 10
Reacted by Javier Gonzalez, Carson Howard, Kyℓe Hensel, mcgradty, Maxim Kropotov and SensationSama
Metadata
Metadata
Assignees
Labels
child_processIssues and PRs related to the child_process subsystem.Issues and PRs related to the child_process subsystem.windowsIssues and PRs related to the Windows platform.Issues and PRs related to the Windows platform.
Activity
addaleax commentedon Jan 16, 2017
/cc @nodejs/platform-windows
seishun commentedon Jan 16, 2017
See also #5620
Fishrock123 commentedon Jan 16, 2017
Does changing the spawn option to
'inherit'for stdin make any difference?segrey commentedon Jan 16, 2017
@Fishrock123 If you meant changing middle.js, like
Then, no, it doesn't make any difference for me.
As for changing main.js, it's will change the behavior, yes. However, middle.js is executed with piped standard streams (not tty) in my environment, so it's impossible to make this change for me.
Fishrock123 commentedon Jan 16, 2017
Correct. Just making sure there wasn't any hidden Windows logic in
inherit.win, pipe: avoid synchronous pipe deadlocks
win, pipe: avoid synchronous pipe deadlocks
win, pipe: avoid synchronous pipe deadlocks
win, pipe: avoid synchronous pipe deadlocks
win, pipe: avoid synchronous pipe deadlocks
Trott commentedon Jul 15, 2017
@bzoz Is fixing this likely blocked by until libuv/libuv#1273 or equivalent lands in libuv and the appropriate version of libuv gets upstreamed to our
depsdirectory?bzoz commentedon Jul 17, 2017
Yes
win, pipe: avoid synchronous pipe deadlocks
6 remaining items
test: stdio pipe behavior tests
test: stdio pipe behavior tests
test: stdio pipe behavior tests
test: stdio pipe behavior tests
test: stdio pipe behavior tests
test: stdio pipe behavior tests
test: stdio pipe behavior tests
test: stdio pipe behavior tests
test: stdio pipe behavior tests