Skip to content

Commit

Permalink
child_process.flushStdio: resume _consuming streams
Browse files Browse the repository at this point in the history
When a client calls read() with a nonzero argument
on a Socket, that Socket sets this._consuming to true.
It never sets this._consuming back to false.
child_process.flushStdio currently doesn't flush
any streams where _consuming is truthy. But that means
that it never flushes any stream that has ever been read from.
This prevents a child process from ever closing if one of
its streams has been read from, causing issue nodejs#4049.

child_process.flushStdio should flush streams even if their
_consuming is set to true. Then it will close even after a read.
  • Loading branch information
Dave committed Nov 30, 2015
1 parent d1000b4 commit f2c8cb5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ util.inherits(ChildProcess, EventEmitter);
function flushStdio(subprocess) {
if (subprocess.stdio == null) return;
subprocess.stdio.forEach(function(stream, fd, stdio) {
if (!stream || !stream.readable || stream._consuming)
if (!stream || !stream.readable)
return;
stream.resume();
});
Expand Down
13 changes: 13 additions & 0 deletions test/sequential/test-child-process-flush-stdio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';
const cp = require('child_process');
const common = require('../common');

var p = cp.spawn('yes');

p.on('close', common.mustCall(function() {}));

p.stdout.read();

setTimeout(function() {
p.kill();
}, 100);

0 comments on commit f2c8cb5

Please sign in to comment.