diff --git a/lib/internal/process/stdio.js b/lib/internal/process/stdio.js index 45568ae631698b..7faef381f895bf 100644 --- a/lib/internal/process/stdio.js +++ b/lib/internal/process/stdio.js @@ -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;