Skip to content

Commit 11c1bae

Browse files
committed
lib: make --debug-port work with cluster
Make the cluster module intercept the `--debug-port=<port>` command line switch and replace it with the debug port of the child process. A happy coincidence of this change is that it finally makes it possible to run the sequential/test-debug-signal-cluster in parallel, it now no longer needs the default port numbers. PR-URL: #306 Reviewed-By: Miroslav Bajtoš <[email protected]>
1 parent 5ec5fd8 commit 11c1bae

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

lib/cluster.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ function masterInit() {
308308
workerEnv.NODE_UNIQUE_ID = '' + id;
309309

310310
for (var i = 0; i < execArgv.length; i++) {
311-
var match = execArgv[i].match(/^(--debug|--debug-brk)(=\d+)?$/);
311+
var match = execArgv[i].match(/^(--debug|--debug-(brk|port))(=\d+)?$/);
312312

313313
if (match) {
314314
execArgv[i] = match[1] + '=' + debugPort;

test/sequential/test-debug-signal-cluster.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ var common = require('../common');
2323
var assert = require('assert');
2424
var spawn = require('child_process').spawn;
2525

26-
var args = [ common.fixturesDir + '/clustered-server/app.js' ];
27-
var child = spawn(process.execPath, args, {
28-
stdio: [ 'pipe', 'pipe', 'pipe', 'ipc' ]
29-
});
26+
var port = common.PORT + 42;
27+
var args = ['--debug-port=' + port,
28+
common.fixturesDir + '/clustered-server/app.js'];
29+
var options = { stdio: ['inherit', 'inherit', 'pipe', 'ipc'] };
30+
var child = spawn(process.execPath, args, options);
31+
3032
var outputLines = [];
3133
var outputTimerId;
3234
var waitingForDebuggers = false;
@@ -83,11 +85,11 @@ process.on('exit', function onExit() {
8385
function assertOutputLines() {
8486
var expectedLines = [
8587
'Starting debugger agent.',
86-
'Debugger listening on port ' + 5858,
88+
'Debugger listening on port ' + (port + 0),
8789
'Starting debugger agent.',
88-
'Debugger listening on port ' + 5859,
90+
'Debugger listening on port ' + (port + 1),
8991
'Starting debugger agent.',
90-
'Debugger listening on port ' + 5860,
92+
'Debugger listening on port ' + (port + 2),
9193
];
9294

9395
// Do not assume any particular order of output messages,

0 commit comments

Comments
 (0)