Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: prevent workers outliving parent #9257

Merged
merged 1 commit into from
Oct 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions test/sequential/test-child-process-pass-fd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}