-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added inspect port overriding in cluster #13761
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ cluster.SCHED_RR = SCHED_RR; // Master distributes connections. | |
var ids = 0; | ||
var debugPortOffset = 1; | ||
var initialized = false; | ||
let debugSettingsOverriden = false; | ||
|
||
// XXX(bnoordhuis) Fold cluster.schedulingPolicy into cluster.settings? | ||
var schedulingPolicy = { | ||
|
@@ -41,15 +42,15 @@ if (schedulingPolicy === undefined) { | |
|
||
cluster.schedulingPolicy = schedulingPolicy; | ||
|
||
cluster.setupMaster = function(options) { | ||
cluster.setupMaster = function(options = {}) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a silly one, but this might be a breaking change, but IMHO we should keep it unless someone objects. > require('cluster').setupMaster.length
1
> (function a(a1) {}).length
1
> (function b(b1={}) {}).length
0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is definitely a breaking change, albeit a subtle one. Setting an argument default necessarily makes this semver-major There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jasnell Can you explain why? It’s not obvious to me how this would break code that isn’t designed specifically to be broken by this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why its backwards incompatible, but it is unnecessary, as is |
||
var settings = { | ||
args: process.argv.slice(2), | ||
exec: process.argv[1], | ||
execArgv: process.execArgv, | ||
silent: false | ||
}; | ||
util._extend(settings, cluster.settings); | ||
util._extend(settings, options || {}); | ||
util._extend(settings, options); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1, the |
||
|
||
// Tell V8 to write profile data for each process to a separate file. | ||
// Without --logfile=v8-%p.log, everything ends up in a single, unusable | ||
|
@@ -60,6 +61,14 @@ cluster.setupMaster = function(options) { | |
settings.execArgv = settings.execArgv.concat(['--logfile=v8-%p.log']); | ||
} | ||
|
||
// This allows user to override inspect port for workers. | ||
const debugPortArgsRegex = /--inspect(=|-port=)|--debug-port=/; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const debugOverrideInSettings = options.execArgv && options.execArgv.some((arg) => arg.match(debugPortArgsRegex))
settings.execArgv[kDebugSettingsInArgv] = settings.execArgv.some((arg) => arg.match(/--inspect(?:-brk|-port)?|--debug-port/))) Or some variation of... Then reuse |
||
|
||
if (!debugSettingsOverriden && options.execArgv && | ||
options.execArgv.some((arg) => arg.match(debugPortArgsRegex))) { | ||
debugSettingsOverriden = true; | ||
} | ||
|
||
cluster.settings = settings; | ||
|
||
if (initialized === true) | ||
|
@@ -103,7 +112,8 @@ function createWorkerProcess(id, env) { | |
util._extend(workerEnv, env); | ||
workerEnv.NODE_UNIQUE_ID = '' + id; | ||
|
||
if (execArgv.some((arg) => arg.match(debugArgRegex))) { | ||
if (!debugSettingsOverriden && | ||
execArgv.some((arg) => arg.match(debugArgRegex))) { | ||
execArgv.push(`--inspect-port=${process.debugPort + debugPortOffset}`); | ||
debugPortOffset++; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a global, augh...
💡
🤓
create a
Symbol
and hang it oncluster.settings
What the heck, hang them all (maybe in the different PR though)