mirror of
https://github.com/nodejs/node.git
synced 2025-08-16 06:08:50 +02:00
child_process: flush consuming streams
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. ChildProcess.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 #4049. This commit allows consuming streams to be flushed, and the child process to emit a close event. Fixes: https://github.com/nodejs/node/issues/4049 PR-URL: https://github.com/nodejs/node/pull/4071 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
b3313aa603
commit
34b535f4ca
2 changed files with 18 additions and 1 deletions
|
@ -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();
|
||||
});
|
||||
|
|
17
test/parallel/test-child-process-flush-stdio.js
Normal file
17
test/parallel/test-child-process-flush-stdio.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
'use strict';
|
||||
const cp = require('child_process');
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const p = cp.spawn('echo');
|
||||
|
||||
p.on('close', common.mustCall(function(code, signal) {
|
||||
assert.strictEqual(code, 0);
|
||||
assert.strictEqual(signal, null);
|
||||
}));
|
||||
|
||||
p.stdout.read();
|
||||
|
||||
setTimeout(function() {
|
||||
p.kill();
|
||||
}, 100);
|
Loading…
Add table
Add a link
Reference in a new issue