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

Conversation

sameer-coder
Copy link
Contributor

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
  • [x ] make -j4 test (UNIX), or vcbuild test (Windows) passes
  • [x ] tests and/or benchmarks are included
  • [x ] commit message follows commit guidelines

Affected core subsystem(s)

  • cluster

@nodejs-github-bot nodejs-github-bot added the cluster Issues and PRs related to the cluster subsystem. label Mar 6, 2018
@sameer-coder sameer-coder changed the title cluster: cluster: Add support to cluster to work with `NODE_OPTIONS="--inspect" Mar 6, 2018
@sameer-coder sameer-coder reopened this Mar 6, 2018
@benjamingr benjamingr added the inspector Issues and PRs related to the V8 inspector protocol label Mar 6, 2018
@benjamingr
Copy link
Member

Thanks for doing this!

@nodejs/v8-inspector @nodejs/cluster

Copy link
Member

@richardlau richardlau left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this. Left a few comments. The test probably should be spawning more than one worker to properly test #19026 just like the test added in #13619.

@@ -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(' ') : [];
Copy link
Member

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.

Copy link
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 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');

Copy link
Member

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()?

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

@sameer-coder
Copy link
Contributor Author

@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.

Copy link
Contributor

@cjihrig cjihrig left a 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);
Copy link
Contributor

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);
Copy link
Contributor

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?

@sameer-coder
Copy link
Contributor Author

@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\
Copy link
Member

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.

Copy link
Contributor Author

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.

@sameer-coder
Copy link
Contributor Author

sameer-coder commented Mar 12, 2018

Did anyone get a chance to review this again?
I have updated the code as per all the suggestions

@benjamingr benjamingr added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 12, 2018
@benjamingr
Copy link
Member

Added the author-ready tag - should land soon :)

@Trott
Copy link
Member

Trott commented Mar 13, 2018

Copy link
Member

@richardlau richardlau left a 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;
Copy link
Member

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).

Copy link
Member

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.

Copy link
Contributor Author

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) {
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));

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

…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));
Copy link
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
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.

const numWorkers added to specify number of workers spawned
in test-inspect-support-for-node_options. PR nodejs#19165

Fixes : nodejs#19026
@richardlau
Copy link
Member

@richardlau
Copy link
Member

Windows failure is #19263 and unrelated to this PR.

richardlau pushed a commit that referenced this pull request Mar 21, 2018
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>
@richardlau
Copy link
Member

Landed in 9b34ea6.

@richardlau richardlau closed this Mar 21, 2018
@richardlau
Copy link
Member

Congratulations @sameer-coder on your first contribution to Node.js. 🎉

@sameer-coder
Copy link
Contributor Author

Thank you very much @richardlau for the opportunity to pick this up and then helping with the code.
I am absolutely thrilled at my first contribution and look forward to contributing more!

targos pushed a commit that referenced this pull request Mar 24, 2018
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>
targos added a commit that referenced this pull request Mar 27, 2018
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
MylesBorins pushed a commit that referenced this pull request Mar 28, 2018
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. cluster Issues and PRs related to the cluster subsystem. inspector Issues and PRs related to the V8 inspector protocol
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cluster fails with NODE_OPTIONS="--inspect"
7 participants