-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Conversation
Thanks for doing this! @nodejs/v8-inspector @nodejs/cluster |
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.
lib/internal/cluster/master.js
Outdated
@@ -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.split(' ') : []; |
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.
There's no need to split NODE_OPTIONS
. Later on match()
can be called on the whole string.
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.
@richardlau I have removed the split and doing a direct match. Please review again.
|
||
if (process.config.variables.node_without_node_options) | ||
common.skip('missing NODE_OPTIONS support'); | ||
|
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.
Could you also call common.skipIfInspectorDisabled()
?
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.
Done
@richardlau Thanks for your comments. I am re-writing the test to spawn more workers like how its done in test-inspector-port-cluster.js test. Will get back to you. |
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.
LGTM with nits addressed.
cluster.fork(env); | ||
|
||
cluster.on('online', (worker) => { | ||
process.exit(0); |
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.
Please don't call process.exit()
. Instead, disconnect the worker and let the test exit naturally.
|
||
function checkForInspectSupport(flag) { | ||
const env = Object.assign({}, process.env, { NODE_OPTIONS: flag }); | ||
const o = JSON.stringify(flag); |
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.
Could you use a more meaningful name than o
?
@richardlau - I have updated the code to match the entire options string and also added common.skipIfInspectorDisabled(). Also, I have changed the test so that it spawns multiple workers now. @cjihrig - I have made changes as per your comments to use worker disconnect instead of process.exit() |
}); | ||
|
||
cluster.on('exit', (worker, code, signal) => { | ||
assert.fail(`For ${o}, failed to start a cluster with inspect option`); | ||
if (worker.exitedAfterDisconnect === false) { | ||
assert.fail(`For ${nodeOptions}, failed to start cluster\ |
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.
Nit: please avoid using multiline template strings.
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.
@jasnell I have changed the code. No longer using multiline string. Please review again.
Did anyone get a chance to review this again? |
Added the author-ready tag - should land soon :) |
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.
Sorry, thought I'd re-reviewed this.
I think we also moved some of the inspector tests to sequential because they were otherwise competing for port 9229 when run in parallel.
const common = require('../common'); | ||
const cluster = require('cluster'); | ||
const assert = require('assert'); | ||
const numCPUs = require('os').cpus().length; |
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.
This needs to be a minimum of 2 to properly test #19026 (i.e. if numCPUs
is 1
then the test will pass without the corresponding lib/internal/cluster/master.js
changes).
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.
To clarify, by "this" I mean the number of workers spawned in the subsequent for loop.
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.
@richardlau you are right. I am no longer using numCPUs and directly spawning multiple workers.
When using cluster and --inspect as cli argument it is correctly handled and each worker will use a different port, this was fixed by nodejs#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: nodejs#19026
…k with NODE_OPTIONS="--inspect" When using cluster and --inspect as cli argument it is correctly handled and each worker will use a different port, this was fixed by nodejs#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: nodejs#19026
…or-node_options Changed multi-line template string in test-inspect-support-for-node_options as per feedback from @jasnell. PR nodejs#19165 Fixes : nodejs#19026
…ptions Removed numCpus and hardcoded to spawn multiple workers in test-inspect-support-for-node_options. PR nodejs#19165 Fixes : nodejs#19026
}); | ||
|
||
cluster.on('exit', (worker, code, signal) => { | ||
if (worker.exitedAfterDisconnect === false) { |
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.
Should this be an assert rather than if-fail?
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.
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));
worker.disconnect(); | ||
}); | ||
|
||
cluster.on('exit', (worker, code, signal) => { |
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.
Wrap the callback in common.mustCall
.
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.
Done
…rt-for-node_options Using common.mustCall to wrap callback and added assert to replace if-fail in test-inspect-support-for-node_options. PR nodejs#19165 Fixes : nodejs#19026
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)); |
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.
Tiny nit: maybe make the 2
here and in the for loop that forks the workers a const since they should match?
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.
@richardlau I have added the const and replaced the 2
both in the for loop and callback.
const numWorkers added to specify number of workers spawned in test-inspect-support-for-node_options. PR nodejs#19165 Fixes : nodejs#19026
Windows failure is #19263 and unrelated to this PR. |
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: #19026 PR-URL: #19165 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Landed in 9b34ea6. |
Congratulations @sameer-coder on your first contribution to Node.js. 🎉 |
Thank you very much @richardlau for the opportunity to pick this up and then helping with the code. |
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: #19026 PR-URL: #19165 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Notable changes: * cluster: - Add support for `NODE_OPTIONS="--inspect"` (Sameer Srivastava) #19165 * crypto: - Expose the public key of a certificate (Hannes Magnusson) #17690 * n-api: - Add `napi_fatal_exception` to trigger an `uncaughtException` in JavaScript (Mathias Buus) #19337 * path: - Fix regression in `posix.normalize` (Michaël Zasso) #19520 * stream: - Improve stream creation performance (Brian White) #19401 * Added new collaborators - [BethGriggs](https://github.com/BethGriggs) Beth Griggs
This is a security release. All Node.js users should consult the security release summary at: https://nodejs.org/en/blog/vulnerability/march-2018-security-releases/ for details on patched vulnerabilities. Fixes for the following CVEs are included in this release: * CVE-2018-7158 * CVE-2018-7159 * CVE-2018-7160 Notable changes: * Upgrade to OpenSSL 1.0.2o: Does not contain any security fixes that are known to impact Node.js. * **Fix for inspector DNS rebinding vulnerability (CVE-2018-7160)**: A malicious website could use a DNS rebinding attack to trick a web browser to bypass same-origin-policy checks and allow HTTP connections to localhost or to hosts on the local network, potentially to an open inspector port as a debugger, therefore gaining full code execution access. The inspector now only allows connections that have a browser `Host` value of `localhost` or `localhost6`. * **Fix for `'path'` module regular expression denial of service (CVE-2018-7158)**: A regular expression used for parsing POSIX an Windows paths could be used to cause a denial of service if an attacker were able to have a specially crafted path string passed through one of the impacted `'path'` module functions. * **Reject spaces in HTTP `Content-Length` header values (CVE-2018-7159)**: The Node.js HTTP parser allowed for spaces inside `Content-Length` header values. Such values now lead to rejected connections in the same way as non-numeric values. * **Update root certificates**: 5 additional root certificates have been added to the Node.js binary and 30 have been removed. * cluster: - Add support for `NODE_OPTIONS="--inspect"` (Sameer Srivastava) #19165 * crypto: - Expose the public key of a certificate (Hannes Magnusson) #17690 * n-api: - Add `napi_fatal_exception` to trigger an `uncaughtException` in JavaScript (Mathias Buus) #19337 * path: - Fix regression in `posix.normalize` (Michaël Zasso) #19520 * stream: - Improve stream creation performance (Brian White) #19401 * Added new collaborators - [BethGriggs](https://github.com/BethGriggs) Beth Griggs PR-URL: https://github.com/nodejs-private/node-private/pull/111
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: #19026
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)