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

child_process: emit IPC messages on next tick #6909

Merged
merged 4 commits into from
May 24, 2016
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,11 @@ function workerInit() {
const handle = handles[key];
delete handles[key];
waitingCount++;
handle.owner.close(checkWaitingCount);

if (handle.owner)
handle.owner.close(checkWaitingCount);
else
handle.close(checkWaitingCount);
}

checkWaitingCount();
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,9 @@ function handleMessage(target, message, handle) {
message.cmd.slice(0, INTERNAL_PREFIX.length) === INTERNAL_PREFIX) {
eventName = 'internalMessage';
}
target.emit(eventName, message, handle);
process.nextTick(() => {
target.emit(eventName, message, handle);
});
}

function nop() { }
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-cluster-ipc-throw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
const common = require('../common');
const http = require('http');
const cluster = require('cluster');

cluster.schedulingPolicy = cluster.SCHED_RR;

const server = http.createServer();

if (cluster.isMaster) {
server.listen(common.PORT);
const worker = cluster.fork();
worker.on('exit', common.mustCall(() => {
server.close();
}));
} else {
process.on('uncaughtException', common.mustCall((e) => {}));
server.listen(common.PORT);
server.on('error', common.mustCall((e) => {
cluster.worker.disconnect();
throw e;
}));
}
20 changes: 20 additions & 0 deletions test/parallel/test-cluster-worker-disconnect-on-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
const common = require('../common');
const http = require('http');
const cluster = require('cluster');

cluster.schedulingPolicy = cluster.SCHED_NONE;

const server = http.createServer();
if (cluster.isMaster) {
server.listen(common.PORT);
const worker = cluster.fork();
worker.on('exit', common.mustCall(() => {
server.close();
}));
} else {
server.listen(common.PORT);
server.on('error', common.mustCall((e) => {
cluster.worker.disconnect();
}));
}