child_process: fire close event from stdio
PR-URL: https://github.com/nodejs/node/pull/22892 Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
82a256ac67
commit
1133e0bf8b
@ -387,6 +387,9 @@ ChildProcess.prototype.spawn = function(options) {
|
|||||||
// The stream is already cloned and piped, thus close it.
|
// The stream is already cloned and piped, thus close it.
|
||||||
if (stream.type === 'wrap') {
|
if (stream.type === 'wrap') {
|
||||||
stream.handle.close();
|
stream.handle.close();
|
||||||
|
if (stream._stdio && stream._stdio instanceof EventEmitter) {
|
||||||
|
stream._stdio.emit('close');
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -946,7 +949,8 @@ function _validateStdio(stdio, sync) {
|
|||||||
acc.push({
|
acc.push({
|
||||||
type: 'wrap',
|
type: 'wrap',
|
||||||
wrapType: getHandleWrapType(handle),
|
wrapType: getHandleWrapType(handle),
|
||||||
handle: handle
|
handle: handle,
|
||||||
|
_stdio: stdio
|
||||||
});
|
});
|
||||||
} else if (isArrayBufferView(stdio) || typeof stdio === 'string') {
|
} else if (isArrayBufferView(stdio) || typeof stdio === 'string') {
|
||||||
if (!sync) {
|
if (!sync) {
|
||||||
|
20
test/parallel/test-child-process-server-close.js
Normal file
20
test/parallel/test-child-process-server-close.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const common = require('../common');
|
||||||
|
const { spawn } = require('child_process');
|
||||||
|
const net = require('net');
|
||||||
|
|
||||||
|
const server = net.createServer((conn) => {
|
||||||
|
conn.on('close', common.mustCall());
|
||||||
|
|
||||||
|
spawn(process.execPath, ['-v'], {
|
||||||
|
stdio: ['ignore', conn, 'ignore']
|
||||||
|
}).on('close', common.mustCall());
|
||||||
|
}).listen(common.PIPE, () => {
|
||||||
|
const client = net.connect(common.PIPE, common.mustCall());
|
||||||
|
client.on('data', () => {
|
||||||
|
client.end(() => {
|
||||||
|
server.close();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user