Skip to content

Commit 8c864de

Browse files
koh110BridgeAR
authored andcommitted
child_process: fire close event from stdio
PR-URL: #22892 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 2b2471b commit 8c864de

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎lib/internal/child_process.js‎

Lines changed: 5 additions & 1 deletion
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._stdioinstanceofEventEmitter){
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
}elseif(isArrayBufferView(stdio)||typeofstdio==='string'){
952956
if(!sync){
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
const{ spawn }=require('child_process');
5+
constnet=require('net');
6+
7+
constserver=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+
constclient=net.connect(common.PIPE,common.mustCall());
15+
client.on('data',()=>{
16+
client.end(()=>{
17+
server.close();
18+
});
19+
});
20+
});

0 commit comments

Comments
 (0)