summaryrefslogtreecommitdiff
path: root/test/sequential/test-child-process-pass-fd.js
diff options
context:
space:
mode:
authorSam Roberts <vieuxtech@gmail.com>2016-10-24 08:53:42 -0700
committerSam Roberts <vieuxtech@gmail.com>2016-10-27 09:49:06 -0700
commit4d896c44f3a0b5f824a4d2971d96b29f3df69e23 (patch)
tree4c8699197bb7596c39bd34175d8499a0249a2b28 /test/sequential/test-child-process-pass-fd.js
parentde24c45de7703c1813526a986c3272b3a0b6a7f0 (diff)
downloadandroid-node-v8-4d896c44f3a0b5f824a4d2971d96b29f3df69e23.tar.gz
android-node-v8-4d896c44f3a0b5f824a4d2971d96b29f3df69e23.tar.bz2
android-node-v8-4d896c44f3a0b5f824a4d2971d96b29f3df69e23.zip
test: prevent workers outliving parent
test-child-process-pass-fd.js parent can exit with an error on failure to fork, in which case it will leak child processes. Limit child lifetime to that of parent. Fixes: https://github.com/nodejs/node/issues/9255 PR-URL: https://github.com/nodejs/node/pull/9257 Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/sequential/test-child-process-pass-fd.js')
-rw-r--r--test/sequential/test-child-process-pass-fd.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/test/sequential/test-child-process-pass-fd.js b/test/sequential/test-child-process-pass-fd.js
index c1d115f9a9..404ae854a1 100644
--- a/test/sequential/test-child-process-pass-fd.js
+++ b/test/sequential/test-child-process-pass-fd.js
@@ -39,15 +39,23 @@ if (process.argv[2] !== 'child') {
process.send('handle', socket);
}
+ // As a side-effect, listening for the message event will ref the IPC channel,
+ // so the child process will stay alive as long as it has a parent process/IPC
+ // channel. Once this is done, we can unref our client and server sockets, and
+ // the only thing keeping this worker alive will be IPC. This is important,
+ // because it means a worker with no parent will have no referenced handles,
+ // thus no work to do, and will exit immediately, preventing process leaks.
+ process.on('message', function() {});
+
const server = net.createServer((c) => {
process.once('message', function(msg) {
assert.strictEqual(msg, 'got');
c.end('hello');
});
socketConnected();
- });
+ }).unref();
server.listen(0, common.localhostIPv4, () => {
const port = server.address().port;
- socket = net.connect(port, common.localhostIPv4, socketConnected);
+ socket = net.connect(port, common.localhostIPv4, socketConnected).unref();
});
}