diff options
author | Brian White <mscdex@mscdex.net> | 2016-02-02 00:57:24 -0500 |
---|---|---|
committer | Brian White <mscdex@mscdex.net> | 2016-02-11 10:47:36 -0500 |
commit | 12274a5c1b0a85f6f8eaf3f6e5c78b1de7617dfc (patch) | |
tree | 8ecea40dbfa6eb98933e49659a7a56dd05895a96 /test/parallel/test-child-process-flush-stdio.js | |
parent | ae244a26c1364857752db2aa79ef1a4a80912459 (diff) | |
download | android-node-v8-12274a5c1b0a85f6f8eaf3f6e5c78b1de7617dfc.tar.gz android-node-v8-12274a5c1b0a85f6f8eaf3f6e5c78b1de7617dfc.tar.bz2 android-node-v8-12274a5c1b0a85f6f8eaf3f6e5c78b1de7617dfc.zip |
child_process: fix data loss with readable event
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>
Diffstat (limited to 'test/parallel/test-child-process-flush-stdio.js')
-rw-r--r-- | test/parallel/test-child-process-flush-stdio.js | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/test/parallel/test-child-process-flush-stdio.js b/test/parallel/test-child-process-flush-stdio.js index 5fd7eb3bc9..dacc1226f3 100644 --- a/test/parallel/test-child-process-flush-stdio.js +++ b/test/parallel/test-child-process-flush-stdio.js @@ -8,10 +8,22 @@ 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(); -setTimeout(function() { - p.kill(); -}, 100); +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); + }); +} |