Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
cluster: sometimes debug-port value for child process can be broken
In case of long running cluster, if worker processes is restarting
periodically, --debug-port value may become out of range [1024, 65535].
  • Loading branch information
Olegas committed Apr 25, 2015
commit cd23c8850b19468235459ea6ca968b75d0c46da2
3 changes: 2 additions & 1 deletion lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cluster.Worker = Worker;
cluster.isWorker = ('NODE_UNIQUE_ID' in process.env);
cluster.isMaster = (cluster.isWorker === false);

const debugPortRange = (65536 - 1024);

function Worker(options) {
if (!(this instanceof Worker))
Expand Down Expand Up @@ -282,7 +283,7 @@ function masterInit() {
function createWorkerProcess(id, env) {
var workerEnv = util._extend({}, process.env);
var execArgv = cluster.settings.execArgv.slice();
var debugPort = process.debugPort + id;
var debugPort = (process.debugPort + id) % debugPortRange + 1024;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be a little neater to turn the number literal into a constant and use it in the range calculation above.

Aside, it's something of a (not consistently enforced) convention to name constants kFoo, i.e.:

const kDebugPortStart = 1024;
const kDebugPortRange = (65536 - kDebugPortStart);

var hasDebugArg = false;

workerEnv = util._extend(workerEnv, env);
Expand Down