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.

Refs: libuv/libuv#1851
Refs: libuv/libuv#1897
PR-URL: nodejs#21466
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
cjihrig authored and MylesBorins committed Nov 5, 2018
1 parent 49910ce commit de6095c
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/internal/process/stdio.js
Original file line number Diff line number Diff line change
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 de6095c

Please sign in to comment.