diff --git a/lib/cluster.js b/lib/cluster.js index 22d213ba227e2a..77726079602a64 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -299,6 +299,7 @@ function masterInit() { function createWorkerProcess(id, env) { var workerEnv = util._extend({}, process.env); var execArgv = cluster.settings.execArgv.slice(); + var debugPort = 0; workerEnv = util._extend(workerEnv, env); workerEnv.NODE_UNIQUE_ID = '' + id; @@ -307,8 +308,11 @@ function masterInit() { var match = execArgv[i].match(/^(--debug|--debug-(brk|port))(=\d+)?$/); if (match) { - const debugPort = process.debugPort + debugPortOffset; - ++debugPortOffset; + if (debugPort === 0) { + debugPort = process.debugPort + debugPortOffset; + ++debugPortOffset; + } + execArgv[i] = match[1] + '=' + debugPort; } } diff --git a/test/parallel/test-cluster-debug-port.js b/test/parallel/test-cluster-debug-port.js index e8f3f58b9534db..70203124ef0f66 100644 --- a/test/parallel/test-cluster-debug-port.js +++ b/test/parallel/test-cluster-debug-port.js @@ -22,6 +22,11 @@ if (cluster.isMaster) { portSet: process.debugPort + 1 }).on('exit', checkExitCode); + cluster.setupMaster({ + execArgv: [`--debug-port=${process.debugPort}`, + `--debug=${process.debugPort}`] + }); + console.log('forked worker should have --debug-port, with offset = 2'); cluster.fork({ portSet: process.debugPort + 2