Skip to content
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

cluster: Add support to cluster to work with `NODE_OPTIONS="--inspect" #19165

Closed
wants to merge 6 commits into from
5 changes: 4 additions & 1 deletion lib/internal/cluster/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,14 @@ function createWorkerProcess(id, env) {
const workerEnv = util._extend({}, process.env);
const execArgv = cluster.settings.execArgv.slice();
const debugArgRegex = /--inspect(?:-brk|-port)?|--debug-port/;
const nodeOptions = process.env.NODE_OPTIONS ?
process.env.NODE_OPTIONS : '';

util._extend(workerEnv, env);
workerEnv.NODE_UNIQUE_ID = '' + id;

if (execArgv.some((arg) => arg.match(debugArgRegex))) {
if (execArgv.some((arg) => arg.match(debugArgRegex)) ||
nodeOptions.match(debugArgRegex)) {
let inspectPort;
if ('inspectPort' in cluster.settings) {
if (typeof cluster.settings.inspectPort === 'function')
Expand Down
30 changes: 30 additions & 0 deletions test/parallel/test-inspect-support-for-node_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';
const common = require('../common');
const cluster = require('cluster');
const assert = require('assert');

common.skipIfInspectorDisabled();

checkForInspectSupport('--inspect');

function checkForInspectSupport(flag) {

const nodeOptions = JSON.stringify(flag);
process.env.NODE_OPTIONS = flag;

if (cluster.isMaster) {
for (let i = 0; i < 2; i++) {
cluster.fork();
}

cluster.on('online', (worker) => {
worker.disconnect();
});

cluster.on('exit', (worker, code, signal) => {
Copy link
Member

Choose a reason for hiding this comment

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

Wrap the callback in common.mustCall.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if (worker.exitedAfterDisconnect === false) {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be an assert rather than if-fail?

Copy link
Contributor Author

@sameer-coder sameer-coder Mar 16, 2018

Choose a reason for hiding this comment

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

Does this look ok?

    cluster.on('exit', common.mustCall((worker, code, signal) => {
      const errMsg = `For NODE_OPTIONS ${nodeOptions}, failed to start cluster`;
      assert.strictEqual(worker.exitedAfterDisconnect, true, errMsg);
    }, 2));

assert.fail(`For NODE_OPTIONS ${nodeOptions}, failed to start cluster`);
}
});
}
}