Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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: libuv/libuv#1851
Refs: libuv/libuv#1897
PR-URL: #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
commit de6095cee460000d98544450e1fd32a48bb85d37
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