Skip to content

Commit

Permalink
cluster: do not signal children in debug mode
Browse files Browse the repository at this point in the history
Do not send signal to children if they are already in debug mode.
Node.js on Windows does not register signal handler, and thus calling
`process._debugProcess()` will throw an error.

Reviewed-By: Trevor Norris <trevnorris@gmail.com>
PR-URL: nodejs/node-v0.x-archive#8476
  • Loading branch information
indutny committed Oct 8, 2014
1 parent 6a610a0 commit 3821863
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,34 @@ function masterInit() {
assert(schedulingPolicy === SCHED_NONE || schedulingPolicy === SCHED_RR,
'Bad cluster.schedulingPolicy: ' + schedulingPolicy);

process.on('internalMessage', function(message) {
if (message.cmd !== 'NODE_DEBUG_ENABLED') return;
var key;
for (key in cluster.workers)
process._debugProcess(cluster.workers[key].process.pid);
var hasDebugArg = process.execArgv.some(function(argv) {
return /^(--debug|--debug-brk)(=\d+)?$/.test(argv);
});

process.nextTick(function() {
cluster.emit('setup', settings);
});

// Send debug signal only if not started in debug mode, this helps a lot
// on windows, because RegisterDebugHandler is not called when node starts
// with --debug.* arg.
if (hasDebugArg)
return;

process.on('internalMessage', function(message) {
if (message.cmd !== 'NODE_DEBUG_ENABLED') return;
var key;
for (key in cluster.workers) {
var worker = cluster.workers[key];
if (worker.state === 'online') {
process._debugProcess(worker.process.pid);
} else {
worker.once('online', function() {
process._debugProcess(this.process.pid);
});
}
}
});
};

function createWorkerProcess(id, env) {
Expand Down

0 comments on commit 3821863

Please sign in to comment.