mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
bootstrap: call _undestroy() inside _destroy for stdout and stderr
This change makes `process.stdout` and `process.stderr` to be automatically undestroyed when ended/destrouyed, therefore making it always possible to write/console.log to stdout. Fixes: https://github.com/nodejs/node/issues/39447 PR-URL: https://github.com/nodejs/node/pull/39685 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
1 parent
3914354cd7
commit
33f9b7f80b
2 files changed
+37
No files matched your search
@@ -100,6 +100,7 @@ function createWritableStdioStream(fd) {
|
||||
|
||||
function dummyDestroy(err, cb) {
|
||||
cb(err);
|
||||
this._undestroy();
|
||||
|
||||
// We need to emit 'close' anyway so that the closing
|
||||
// of the stream is observable. We just make sure we
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const spawn = require('child_process').spawn;
|
||||
|
||||
if (process.argv[2] === 'child') {
|
||||
process.stdout.destroy();
|
||||
process.stderr.destroy();
|
||||
console.log('stdout');
|
||||
process.stdout.write('rocks\n');
|
||||
console.error('stderr');
|
||||
setTimeout(function() {
|
||||
process.stderr.write('rocks too\n');
|
||||
}, 10);
|
||||
return;
|
||||
}
|
||||
|
||||
const proc = spawn(process.execPath, [__filename, 'child'], { stdio: 'pipe' });
|
||||
|
||||
let stdout = '';
|
||||
proc.stdout.setEncoding('utf8');
|
||||
proc.stdout.on('data', common.mustCallAtLeast(function(chunk) {
|
||||
stdout += chunk;
|
||||
}, 1));
|
||||
|
||||
let stderr = '';
|
||||
proc.stderr.setEncoding('utf8');
|
||||
proc.stderr.on('data', common.mustCallAtLeast(function(chunk) {
|
||||
stderr += chunk;
|
||||
}, 1));
|
||||
|
||||
proc.on('exit', common.mustCall(function(exitCode) {
|
||||
assert.strictEqual(exitCode, 0);
|
||||
assert.strictEqual(stdout, 'stdout\nrocks\n');
|
||||
assert.strictEqual(stderr, 'stderr\nrocks too\n');
|
||||
}));
|
||||
Reference in new issue
Block a user