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

VS Code attaches to wrong port when using process picker #37985

Closed
jez9999 opened this issue Nov 9, 2017 · 5 comments
Closed

VS Code attaches to wrong port when using process picker #37985

jez9999 opened this issue Nov 9, 2017 · 5 comments
Assignees
Labels
*as-designed Described behavior is as designed debug Debug viewlet, configurations, breakpoints, adapter issues

Comments

@jez9999
Copy link

jez9999 commented Nov 9, 2017

I'm trying to do multi-target debugging. I use a Launch configuration to launch my master process and then use cluster.fork to fork a child process. I then try to start an "Attach to process" debug session, and I pick the forked process (one of whose arguments is --inspect-port=17130. After 10 seconds I get the error:

Ensure Node was launched with --inspect. Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:9229).

It tried to connect to port 9229, and unsurprisingly it didn't work. If I manually set up a launch configuration to attach to port 17130 it works, but why can't the process picker figure out it needs that port?

@vscodebot vscodebot bot added the debug Debug viewlet, configurations, breakpoints, adapter issues label Nov 9, 2017
@weinand
Copy link
Contributor

weinand commented Nov 10, 2017

What you are seeing is the expected behaviour.

The process picker is used to attach to a node process by process ID, not by port.
The idea of the picker is to attach to a node process that was not started with a --inspect flag and consequently has no debug port open. In this case VS Code sends a signal to the node process which starts node's internal debug agent on a fixed port (5858 for node version < 8 and 9222 for node versions >= 8). So when attaching to a node process by ID, you cannot use port 17130 because node uses one of the hardcoded ports anyway.

But in your case the node.js is explicitely started with --inspect=nnnn, so there is no need to pick the process by ID because node can directly connect to the known port of the (one and only) correct process.

So using the attach config for port 17130 is the way to go.

If you really want to use a process picker, then make sure that the processes you want to pick are not started with the --inspect flag.

@weinand weinand closed this as completed Nov 10, 2017
@weinand weinand added the *as-designed Described behavior is as designed label Nov 10, 2017
@jez9999
Copy link
Author

jez9999 commented Nov 10, 2017

@weinand But the port number changes every time, it seems to be random. So you have to change the config every time which is really annoying. Why not add the feature to the process picker that if it detects the --inspect flag it tries to attach on that port instead?

@weinand
Copy link
Contributor

weinand commented Nov 10, 2017

The connection between the process picker and the node-debugger is via a launch config variable ${command:PickProcess} which resolves to a process ID. It is not possible to either return a process ID or a port number and then assign this to the corresponding attributes in a launch config.

Could you try to configure a fixed port for cluster.fork?

@jez9999
Copy link
Author

jez9999 commented Nov 10, 2017

The connection between the process picker and the node-debugger is via a launch config variable ${command:PickProcess} which resolves to a process ID. It is not possible to either return a process ID or a port number and then assign this to the corresponding attributes in a launch config.

You could have a special case where the return value port:xxx overrides the port setting and makes VS Code launch an attach to port instead.

I'm not sure how you configure a port for cluster.fork but it's annoying to have to do so because the number of forks is configurable so at the moment I'm just relying on it automatically picking a free port for each forked process.

@weinand
Copy link
Contributor

weinand commented Nov 10, 2017

The connection between the process picker command and the node-debugger is based on the generic concept of textual variable substitution. That does not support to substitute different attributes in a launch config.

I suggest to continue the discussion here: #3201

@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 25, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*as-designed Described behavior is as designed debug Debug viewlet, configurations, breakpoints, adapter issues
Projects
None yet
Development

No branches or pull requests

2 participants