Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
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
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
29 changes: 29 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,29 @@
'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', common.mustCall((worker, code, signal) => {
const errMsg = `For NODE_OPTIONS ${nodeOptions}, failed to start cluster`;
assert.strictEqual(worker.exitedAfterDisconnect, true, errMsg);
}, 2));
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.

Tiny nit: maybe make the 2 here and in the for loop that forks the workers a const since they should match?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@richardlau I have added the const and replaced the 2 both in the for loop and callback.

}
}