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: fix debugging port collision #12395

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions lib/internal/cluster/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function createWorkerProcess(id, env) {

for (var i = 0; i < execArgv.length; i++) {
const match = execArgv[i].match(
/^(--inspect|--inspect-(brk|port)|--debug|--debug-(brk|port))(=\d+)?$/
/^(--inspect|--inspect-(brk|port)|--debug|--debug-(brk|port))(=.*)?$/
Copy link
Contributor

Choose a reason for hiding this comment

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

This will match flags that specify a host, but it seems like the host would then be lost when the flag is rewritten for the worker process a few lines down.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I'm thinking about addding process._debugHostname to avoid complex regex, what do you think?

diff --git a/lib/internal/cluster/master.js b/lib/internal/cluster/master.js
index c7b06b8..2a7379b 100644
--- a/lib/internal/cluster/master.js
+++ b/lib/internal/cluster/master.js
@@ -124,7 +124,7 @@ function createWorkerProcess(id, env) {
         ++debugPortOffset;
       }

-      execArgv[i] = match[1] + '=' + debugPort;
+      execArgv[i] = match[1] + '=' + process._debugHostname + ':' + debugPort;
     }
   }

diff --git a/src/node.cc b/src/node.cc
index c241f73..f091ac7 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -3361,6 +3361,8 @@ void SetupProcessObject(Environment* env,
                              DebugPortSetter,
                              env->as_external()).FromJust());

+  READONLY_PROPERTY(process, "_debugHostname", OneByteString(env->isolate(), debug_options.host_name().c_str()));
+
   // define various internal methods
   env->SetMethod(process,
                  "_startProfilerIdleNotifier",

);

if (match) {
Expand All @@ -124,7 +124,7 @@ function createWorkerProcess(id, env) {
++debugPortOffset;
}

execArgv[i] = match[1] + '=' + debugPort;
execArgv[i] = match[1] + '=' + process._debugHostname + ':' + debugPort;
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3361,6 +3361,11 @@ void SetupProcessObject(Environment* env,
DebugPortSetter,
env->as_external()).FromJust());

READONLY_PROPERTY(process,
"_debugHostname",
OneByteString(env->isolate(),
debug_options.host_name().c_str()));

// define various internal methods
env->SetMethod(process,
"_startProfilerIdleNotifier",
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-cluster-inspector-debug-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ if (cluster.isMaster) {
fork(4, ['--inspect', `--debug-port=${debuggerPort}`]);
fork(5, [`--inspect-port=${debuggerPort}`]);
fork(6, ['--inspect', `--inspect-port=${debuggerPort}`]);
fork(7, [`--inspect=${common.localhostIPv4}:${debuggerPort}`]);
} else {
const hasDebugArg = process.execArgv.some(function(arg) {
return /inspect/.test(arg);
Expand Down