Skip to content

Commit 8e94cb2

Browse files
koh110BridgeAR
authored andcommitted
child_process: fire close event from stdio
PR-URL: nodejs#22892 Reviewed-By: Anna Henningsen <[email protected]>
1 parent 24b9ae1 commit 8e94cb2

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/internal/child_process.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ ChildProcess.prototype.spawn = function(options) {
386386
// The stream is already cloned and piped, thus close it.
387387
if (stream.type === 'wrap') {
388388
stream.handle.close();
389+
if (stream._stdio && stream._stdio instanceof EventEmitter) {
390+
stream._stdio.emit('close');
391+
}
389392
continue;
390393
}
391394

@@ -946,7 +949,8 @@ function _validateStdio(stdio, sync) {
946949
acc.push({
947950
type: 'wrap',
948951
wrapType: getHandleWrapType(handle),
949-
handle: handle
952+
handle: handle,
953+
_stdio: stdio
950954
});
951955
} else if (isArrayBufferView(stdio) || typeof stdio === 'string') {
952956
if (!sync) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const { spawn } = require('child_process');
5+
const net = require('net');
6+
7+
const server = net.createServer((conn) => {
8+
conn.on('close', common.mustCall());
9+
10+
spawn(process.execPath, ['-v'], {
11+
stdio: ['ignore', conn, 'ignore']
12+
}).on('close', common.mustCall());
13+
}).listen(common.PIPE, () => {
14+
const client = net.connect(common.PIPE, common.mustCall());
15+
client.on('data', () => {
16+
client.end(() => {
17+
server.close();
18+
});
19+
});
20+
});

0 commit comments

Comments
 (0)