Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

cluster: avoid race enabling debugger in worker #9037

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ function masterInit() {
var key;
for (key in cluster.workers) {
var worker = cluster.workers[key];
if (worker.state === 'online') {
if (worker.state === 'online' || worker.state === 'listening') {
process._debugProcess(worker.process.pid);
} else {
worker.once('online', function() {
Expand Down
60 changes: 30 additions & 30 deletions test/simple/test-debug-signal-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,32 @@ var pids = null;

child.stderr.on('data', function(data) {
var lines = data.toString().replace(/\r/g, '').trim().split('\n');
var line = lines[0];

lines.forEach(function(ln) { console.log('> ' + ln) } );
lines.forEach(function(line) {
console.log('> ' + line);

if (outputTimerId !== undefined)
clearTimeout(outputTimerId);
if (line === 'all workers are running') {
child.on('message', function(msg) {
if (msg.type !== 'pids')
return;

if (waitingForDebuggers) {
outputLines = outputLines.concat(lines);
outputTimerId = setTimeout(onNoMoreLines, 800);
} else if (line === 'all workers are running') {
child.on('message', function(msg) {
if (msg.type !== 'pids')
return;
pids = msg.pids;
console.error('got pids %j', pids);

pids = msg.pids;
console.error('got pids %j', pids);
waitingForDebuggers = true;
process._debugProcess(child.pid);
});

waitingForDebuggers = true;
process._debugProcess(child.pid);
});
child.send({
type: 'getpids'
});
} else if (waitingForDebuggers) {
outputLines.push(line);
}

child.send({
type: 'getpids'
});
}
});
if (outputLines.length >= expectedLines.length)
onNoMoreLines();
});

function onNoMoreLines() {
Expand All @@ -70,24 +70,24 @@ function onNoMoreLines() {

setTimeout(function testTimedOut() {
assert(false, 'test timed out.');
}, 6000);
}, 6000).unref();

process.on('exit', function onExit() {
pids.forEach(function(pid) {
process.kill(pid);
});
});

function assertOutputLines() {
var expectedLines = [
'Starting debugger agent.',
'Debugger listening on port ' + 5858,
'Starting debugger agent.',
'Debugger listening on port ' + 5859,
'Starting debugger agent.',
'Debugger listening on port ' + 5860,
];
var expectedLines = [
'Starting debugger agent.',
'Debugger listening on port ' + 5858,
'Starting debugger agent.',
'Debugger listening on port ' + 5859,
'Starting debugger agent.',
'Debugger listening on port ' + 5860,
];

function assertOutputLines() {
// Do not assume any particular order of output messages,
// since workers can take different amout of time to
// start up
Expand Down