mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 19:08:17 +00:00

This commit prevents child process stdio streams from being automatically flushed on child process exit/close if a 'readable' event handler has been attached at the time of exit. Without this, child process stdio data can be lost if the process exits quickly and a `read()` (e.g. from a 'readable' handler) hasn't had the chance to get called yet. Fixes: https://github.com/nodejs/node/issues/5034 PR-URL: https://github.com/nodejs/node/pull/5036 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
30 lines
733 B
JavaScript
30 lines
733 B
JavaScript
'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);
|
|
spawnWithReadable();
|
|
}));
|
|
|
|
p.stdout.read();
|
|
|
|
function spawnWithReadable() {
|
|
const buffer = [];
|
|
const p = cp.spawn('echo', ['123']);
|
|
p.on('close', common.mustCall(function(code, signal) {
|
|
assert.strictEqual(code, 0);
|
|
assert.strictEqual(signal, null);
|
|
assert.strictEqual(Buffer.concat(buffer).toString().trim(), '123');
|
|
}));
|
|
p.stdout.on('readable', function() {
|
|
let buf;
|
|
while (buf = this.read())
|
|
buffer.push(buf);
|
|
});
|
|
}
|