Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0187e3b

Browse filesBrowse files
cjihrigMylesBorins
authored andcommitted
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. 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>
1 parent c54f4bc commit 0187e3b
Copy full SHA for 0187e3b

File tree

Expand file treeCollapse file tree

1 file changed

+18
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-5
lines changed
Open diff view settings
Collapse file

‎lib/internal/process/stdio.js‎

Copy file name to clipboardExpand all lines: lib/internal/process/stdio.js
+18-5Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,24 @@ function createWritableStdioStream(fd) {
161161
case 'PIPE':
162162
case 'TCP':
163163
var net = require('net');
164-
stream = new net.Socket({
165-
fd: fd,
166-
readable: false,
167-
writable: true
168-
});
164+
165+
// If fd is already being used for the IPC channel, libuv will return
166+
// an error when trying to use it again. In that case, create the socket
167+
// using the existing handle instead of the fd.
168+
if (process.channel && process.channel.fd === fd) {
169+
stream = new net.Socket({
170+
handle: process.channel,
171+
readable: false,
172+
writable: true
173+
});
174+
} else {
175+
stream = new net.Socket({
176+
fd,
177+
readable: false,
178+
writable: true
179+
});
180+
}
181+
169182
stream._type = 'pipe';
170183
break;
171184

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.