cluster: rewrite debug ports consistently

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: https://github.com/nodejs/node/pull/7050
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit is contained in:
cjihrig 2016-05-29 14:02:22 -04:00
parent 2369f89a03
commit c4f80c1f34
2 changed files with 11 additions and 2 deletions

View File

@ -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;
@ -309,8 +310,11 @@ function masterInit() {
);
if (match) {
const debugPort = process.debugPort + debugPortOffset;
++debugPortOffset;
if (debugPort === 0) {
debugPort = process.debugPort + debugPortOffset;
++debugPortOffset;
}
execArgv[i] = match[1] + '=' + debugPort;
}
}

View File

@ -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