Skip to content

Commit

Permalink
process: avoid using the same fd for ipc and stdio
Browse files Browse the repository at this point in the history
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.

Backport-PR-URL: #24103
Refs: libuv/libuv#1851
Refs: libuv/libuv#1897
PR-URL: #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>
  • Loading branch information
cjihrig authored and MylesBorins committed Nov 11, 2018
1 parent c54f4bc commit 0187e3b
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/internal/process/stdio.js
Expand Up @@ -161,11 +161,24 @@ function createWritableStdioStream(fd) {
case 'PIPE':
case 'TCP':
var net = require('net');
stream = new net.Socket({
fd: fd,
readable: false,
writable: true
});

// If fd is already being used for the IPC channel, libuv will return
// an error when trying to use it again. In that case, create the socket
// 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';
break;

Expand Down

0 comments on commit 0187e3b

Please sign in to comment.