-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #5034 PR-URL: #5037 Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
2 changed files
with
22 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
var cp = require('child_process'); | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
var buffer = []; | ||
var 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() { | ||
var buf; | ||
while (buf = this.read()) | ||
buffer.push(buf); | ||
}); |