mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 23:52:40 +00:00

When using cluster and --inspect as cli argument it is correctly handled and each worker will use a different port, this was fixed by #13619. But when env var NODE_OPTIONS="--inspect" is set this logic doesn't apply and the workers will fail as they try to attach to the same port. Fixes: https://github.com/nodejs/node/issues/19026 PR-URL: https://github.com/nodejs/node/pull/19165 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
31 lines
758 B
JavaScript
31 lines
758 B
JavaScript
'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);
|
|
const numWorkers = 2;
|
|
process.env.NODE_OPTIONS = flag;
|
|
|
|
if (cluster.isMaster) {
|
|
for (let i = 0; i < numWorkers; 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);
|
|
}, numWorkers));
|
|
}
|
|
}
|