forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cluster: do not unconditionally set --debug-port
Currently, each cluster worker is assigned an ever increasing --debug-port argument. A long running cluster application that does not use the debugger can run into errors related to the port range. This commit mitigates the problem by only setting the debug port if the master is started with debug arguments, or the user explicitly defines debug arguments for the worker. This commit also adds a new debug port offset counter that is only incremented when a worker is created that utilizes debugging. Fixes: nodejs/node-v0.x-archive#8159 Refs: nodejs#1524 PR-URL: nodejs#1949 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Oleg Elifantiev <[email protected]>
- Loading branch information
Showing
2 changed files
with
42 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cluster = require('cluster'); | ||
|
||
if (cluster.isMaster) { | ||
assert.strictEqual(process.execArgv.length, 0, 'run test with no args'); | ||
|
||
function checkExitCode(code, signal) { | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
} | ||
|
||
console.log('forked worker should not have --debug-port'); | ||
cluster.fork().on('exit', checkExitCode); | ||
|
||
cluster.setupMaster({ | ||
execArgv: ['--debug-port=' + process.debugPort] | ||
}); | ||
|
||
console.log('forked worker should have --debug-port, with offset = 1'); | ||
cluster.fork({ | ||
portSet: process.debugPort + 1 | ||
}).on('exit', checkExitCode); | ||
|
||
console.log('forked worker should have --debug-port, with offset = 2'); | ||
cluster.fork({ | ||
portSet: process.debugPort + 2 | ||
}).on('exit', checkExitCode); | ||
} else { | ||
const hasDebugArg = process.execArgv.some(function(arg) { | ||
return /debug/.test(arg); | ||
}); | ||
|
||
assert.strictEqual(hasDebugArg, process.env.portSet !== undefined); | ||
assert.strictEqual(process.debugPort, +process.env.portSet || 5858); | ||
process.exit(); | ||
} |