Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cluster: rewrite debug ports consistently
Browse files Browse the repository at this point in the history
When debug flags are passed to clustered applications, the debug
port is rewritten for each worker process to avoid collisions.
Prior to this commit, each debug flag would get a unique value.
This commit reworks the logic to assign the same port value to
all debug flags for a single worker.

PR-URL: #7050
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
cjihrig authored and MylesBorins committed Jul 12, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 31aded7 commit 4829142
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/cluster.js
Original file line number Diff line number Diff line change
@@ -286,6 +286,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;
@@ -294,8 +295,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;
}
}
5 changes: 5 additions & 0 deletions test/parallel/test-cluster-debug-port.js
Original file line number Diff line number Diff line change
@@ -23,6 +23,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

0 comments on commit 4829142

Please sign in to comment.