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

Attaching to Node running in inspector mode cannot determine version #21104

Closed
michelkaporin opened this issue Feb 22, 2017 · 17 comments
Closed
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug debug Debug viewlet, configurations, breakpoints, adapter issues verified Verification succeeded
Milestone

Comments

@michelkaporin
Copy link
Contributor

michelkaporin commented Feb 22, 2017

While testing #20991:

  • VSCode Version: 1.10.0-insider
  • OS Version: Windows 10 x64
  • Node.js Version: 7.5.0

Steps to Reproduce:

  1. Run node --inspect --debug-brk server.js in shell with simple server.js code.
  2. Have the following launch.json configuration:
        {
            "type": "node",
            "protocol": "auto",
            "request": "attach",
            "name": "Attach to Process",
            "address": "localhost",
            "port": 9229
        }
  1. Run it. The following message is printed: 'Debugging with legacy protocol because Node version could not be determined.'. In addition, legacy protocol does not attach it properly (server.js does not run at all), debug mode terminates automatically without stopping at a breakpoint.

However, launching it in the "request": "launch" mode successfully defaults it to v7.5.0.

Expected Behaviour:
Determine the running version of inspector.

@weinand weinand assigned roblourens and unassigned weinand Feb 22, 2017
@weinand weinand added the debug Debug viewlet, configurations, breakpoints, adapter issues label Feb 22, 2017
@weinand weinand added this to the February 2017 milestone Feb 22, 2017
@weinand weinand added the bug Issue identified by VS Code Team member as probable bug label Feb 22, 2017
@roblourens
Copy link
Member

Before you attach, can you open http://localhost:9229/json/version in your browser? What do you see?

Were you connected to the internet when you tried this?

If you set "protocol": "inspector" does it work?

@michelkaporin
Copy link
Contributor Author

@roblourens Yes, I can open it. This is the data from the link:
{ "Browser": "node.js/v7.5.0", "Protocol-Version": "1.1" }

I was connected to the internet when I tried this.

"protocol": "inspector" works.

@roblourens
Copy link
Member

Is that the full data, like it's not an array?

@michelkaporin
Copy link
Contributor Author

@roblourens yes, it is the full data that I get on that link.

@roblourens
Copy link
Member

Ah, the format of /json/version is different in later node versions. Thanks

@MimoMoreno
Copy link

MimoMoreno commented Jul 24, 2017

Hi,
I have the same problem. I have this configuration:

        {
            "type": "node",
            "request": "attach",
            "protocol": "auto",
            "name": "Attach to Process",
            "port": 5858
        }

And this is the error message:
Debugging with legacy protocol because Node.js version could not be determined (Error: connect ECONNREFUSED 127.0.0.1:5858)

But I can't access to http://localhost:5858/json/version as it was asked to michelkaporin.

@weinand
Copy link
Contributor

weinand commented Jul 24, 2017

@MimoMoreno what version of node are you using and how are you starting node?

@MimoMoreno
Copy link

MimoMoreno commented Jul 24, 2017

@weinand I'm using v6.0.0 and I'm trying to start the debugger from the debug panel (from the activity bar).

@weinand
Copy link
Contributor

weinand commented Jul 24, 2017

@MimoMoreno Your configuration from above does not launch "node". It tries to "attach" to a node process that is already running (that's the reason for the "attach" value of the "request" attribute). If node is not running, debugging will fail with the message you are seeing.

So either you'll have to launch node from the command line, e.g. node --debug-brk myProgram.js or you better use a configuration with request type "launch", e.g. something like this:

{
            "type": "node",
            "request": "launch",
            "protocol": "auto",
            "name": "Launch program",
            "program": "myProgram.js"
}

This will launch your program with node and then attach the debugger to it.

@weinand
Copy link
Contributor

weinand commented Jul 24, 2017

BTW, node v6.0.0 is rather old. I suggest to use a more recent version that includes the recommended security fixes, e.g. v6.11.1 (LTS) or v8.2.1.

@MimoMoreno
Copy link

MimoMoreno commented Jul 24, 2017

@weinand I'm sorry, I didn't put all my configuration. This is it:

       {
            "type": "node",
            "request": "launch",
            "protocol": "auto",
            "name": "Launch Program",
            "program": "${workspaceRoot}/app.js",
            "cwd": "${workspaceRoot}"
        },
        {
            "type": "node",
            "request": "attach",
            "protocol": "auto",
            "name": "Attach to Process",
            "port": 5858
        }

But yet with this configuration I cannot start debugging mode.
We will soon upgrade to version 8!

@weinand
Copy link
Contributor

weinand commented Jul 24, 2017

@MimoMoreno these are two configurations. Which one are you using?

@weinand
Copy link
Contributor

weinand commented Jul 24, 2017

In case you don't know, this drop down menu shows the configuration you are using:

2017-07-24_15-26-58

@MimoMoreno
Copy link

@weinand thanks for that tip! I was using the attach configuration. I changed it to launch program and it worked! So in which case would I use the attach to process configuration?

@weinand
Copy link
Contributor

weinand commented Jul 24, 2017

As I've explained above:

It tries to "attach" to a node process that is already running.

Example: you can launch your node program independent from VS Code from the command line, e.g. as a server process running silently in the background. Suddenly you notice that the server behaves strangely and you want to understand why. You launch VS Code and then run the "Attach to Process" config. Please note that this requires that your node program has been launched with the --debug argument since otherwise the debugger cannot attach to it.

@weinand
Copy link
Contributor

weinand commented Jul 24, 2017

BTW, as you could see now, your problem was completely unrelated to the problem described in this issue.
I suggest not to add a "me too" to another issue but instead create a new issue.
The "me toos" are just making issues difficult to read because one has always to skip around the unrelated discussions. And useful explanations (like mine from above), are now difficult to find because they are buried inside an unrelated issue.

@njcaruso
Copy link

njcaruso commented Aug 7, 2017

Anyone coming to this thread in the future, I had ATTACH working on one project, and not the other. The difference between my two package.json files was I need the "main": "server.js". As soon as I added that, the debugger attached fine.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug debug Debug viewlet, configurations, breakpoints, adapter issues verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

6 participants