Browse Source

internal/child_process: call postSend on error

Call `obj.postSend` in error case of `process.send()`. The
`net.Socket`'s handle should not be leaked.

Note that there are two callbacks invoked on handles
when they are sent to the child process over IPC pipes.
These callbacks are specified by `handleConversion` object, and
during send two of them are invoked:

  * `send`
  * `postSend`

Now for `net.Socket` in particular, `postSend` performs clean up by
closing the actual uv handle. However this clean up will not happen in
one of the branches. This pull request aims to fix this.

PR-URL: https://github.com/nodejs/node/pull/4752
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
v5.x
Fedor Indutny 9 years ago
committed by Rod Vagg
parent
commit
b2c8b7f6d3
  1. 8
      lib/internal/child_process.js

8
lib/internal/child_process.js

@ -602,7 +602,12 @@ function setupChannel(target, channel) {
} else { } else {
process.nextTick(function() { req.oncomplete(); }); process.nextTick(function() { req.oncomplete(); });
} }
} else if (!swallowErrors) { } else {
// Cleanup handle on error
if (obj && obj.postSend)
obj.postSend(handle);
if (!swallowErrors) {
const ex = errnoException(err, 'write'); const ex = errnoException(err, 'write');
if (typeof callback === 'function') { if (typeof callback === 'function') {
process.nextTick(callback, ex); process.nextTick(callback, ex);
@ -610,6 +615,7 @@ function setupChannel(target, channel) {
this.emit('error', ex); // FIXME(bnoordhuis) Defer to next tick. this.emit('error', ex); // FIXME(bnoordhuis) Defer to next tick.
} }
} }
}
/* If the master is > 2 read() calls behind, please stop sending. */ /* If the master is > 2 read() calls behind, please stop sending. */
return channel.writeQueueSize < (65536 * 2); return channel.writeQueueSize < (65536 * 2);

Loading…
Cancel
Save