Skip to content

Commit b2c8b7f

Browse files
indutnyrvagg
authored andcommitted
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: #4752 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 57cea9e commit b2c8b7f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/internal/child_process.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -602,12 +602,18 @@ function setupChannel(target, channel) {
602602
} else {
603603
process.nextTick(function() { req.oncomplete(); });
604604
}
605-
} else if (!swallowErrors) {
606-
const ex = errnoException(err, 'write');
607-
if (typeof callback === 'function') {
608-
process.nextTick(callback, ex);
609-
} else {
610-
this.emit('error', ex); // FIXME(bnoordhuis) Defer to next tick.
605+
} else {
606+
// Cleanup handle on error
607+
if (obj && obj.postSend)
608+
obj.postSend(handle);
609+
610+
if (!swallowErrors) {
611+
const ex = errnoException(err, 'write');
612+
if (typeof callback === 'function') {
613+
process.nextTick(callback, ex);
614+
} else {
615+
this.emit('error', ex); // FIXME(bnoordhuis) Defer to next tick.
616+
}
611617
}
612618
}
613619

0 commit comments

Comments
 (0)