Skip to content

Commit fd98597

Browse files
committed
stdio: call _undestroy() inside _destroy for stdout and stderr
Fixes: #39447
1 parent 712059a commit fd98597

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

lib/internal/bootstrap/switches/is_main_thread.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ function createWritableStdioStream(fd) {
100100

101101
function dummyDestroy(err, cb) {
102102
cb(err);
103+
this._undestroy();
103104

104105
// We need to emit 'close' anyway so that the closing
105106
// of the stream is observable. We just make sure we
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const spawn = require('child_process').spawn;
5+
const fs = require('fs');
6+
const fixtures = require('../common/fixtures');
7+
8+
if (process.argv[2] === 'child') {
9+
process.stdout.destroy()
10+
console.log('out')
11+
console.error('err')
12+
return;
13+
}
14+
15+
// Run the script in a shell but close stdout and stderr.
16+
const cmd = `"${process.execPath}" "${__filename}" child`;
17+
const proc = spawn('/bin/sh', ['-c', cmd], { stdio: 'pipe' });
18+
19+
proc.stdout.on('data', common.mustCall(function(chunk) {
20+
assert.strictEqual(chunk.toString(), 'out\n');
21+
}));
22+
23+
proc.stderr.on('data', common.mustCall(function(chunk) {
24+
assert.strictEqual(chunk.toString(), 'err\n');
25+
}));
26+
27+
proc.on('exit', common.mustCall(function(exitCode) {
28+
assert.strictEqual(exitCode, 0);
29+
}));

0 commit comments

Comments
 (0)