Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
child_process: fix sending handle twice
Browse files Browse the repository at this point in the history
When sending a socket to a child process via IPC pipe,
`child_process.js` picks a raw UV handle from `_handle` property, sends
it, and assigns `null` to the property. Sending the same socket twice
was resulting in a runtime error, since we weren't handling the empty
`_handle` case.

In case of `null` `_handle` we should send just a plain text message
as passed it was passed to `.send()` and ignore the handle, letting
users handle such cases themselves instead of throwing the error at
runtime.

fix #5469
  • Loading branch information
indutny authored and tjfontaine committed Mar 5, 2014
1 parent a9d24fa commit 5e06ce4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/child_process.js
Expand Up @@ -111,6 +111,9 @@ var handleConversion = {


'net.Socket': { 'net.Socket': {
send: function(message, socket) { send: function(message, socket) {
if (!socket._handle)
return;

// if the socket was created by net.Server // if the socket was created by net.Server
if (socket.server) { if (socket.server) {
// the slave should keep track of the socket // the slave should keep track of the socket
Expand Down Expand Up @@ -139,7 +142,8 @@ var handleConversion = {


postSend: function(handle) { postSend: function(handle) {
// Close the Socket handle after sending it // Close the Socket handle after sending it
handle.close(); if (handle)
handle.close();
}, },


got: function(message, handle, emit) { got: function(message, handle, emit) {
Expand Down Expand Up @@ -438,6 +442,11 @@ function setupChannel(target, channel) {
// convert TCP object to native handle object // convert TCP object to native handle object
handle = handleConversion[message.type].send.apply(target, arguments); handle = handleConversion[message.type].send.apply(target, arguments);


// If handle was sent twice, or it is impossible to get native handle
// out of it - just send a text without the handle.
if (!handle)
message = message.msg;

// Update simultaneous accepts on Windows // Update simultaneous accepts on Windows
if (obj.simultaneousAccepts) { if (obj.simultaneousAccepts) {
net._setSimultaneousAccepts(handle); net._setSimultaneousAccepts(handle);
Expand Down

0 comments on commit 5e06ce4

Please sign in to comment.