process: avoid using the same fd for ipc and stdio
There is already a check in place to prevent stdin and the IPC channel from sharing a file descriptor. This commit adds a similar check to stdout and stderr. Refs: https://github.com/libuv/libuv/pull/1851 Refs: https://github.com/libuv/libuv/issues/1897 PR-URL: https://github.com/nodejs/node/pull/21466 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
6396574cde
commit
cb261c8648
@ -183,11 +183,24 @@ function createWritableStdioStream(fd) {
|
|||||||
case 'PIPE':
|
case 'PIPE':
|
||||||
case 'TCP':
|
case 'TCP':
|
||||||
var net = require('net');
|
var net = require('net');
|
||||||
stream = new net.Socket({
|
|
||||||
fd: fd,
|
// If fd is already being used for the IPC channel, libuv will return
|
||||||
readable: false,
|
// an error when trying to use it again. In that case, create the socket
|
||||||
writable: true
|
// using the existing handle instead of the fd.
|
||||||
});
|
if (process.channel && process.channel.fd === fd) {
|
||||||
|
stream = new net.Socket({
|
||||||
|
handle: process.channel,
|
||||||
|
readable: false,
|
||||||
|
writable: true
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
stream = new net.Socket({
|
||||||
|
fd,
|
||||||
|
readable: false,
|
||||||
|
writable: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
stream._type = 'pipe';
|
stream._type = 'pipe';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user