-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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
Node.js debugging - cannot attach debugger to subprocesses #45320
Comments
What version of the node-debug extension are you using? Why am I asking this? |
It's built in isn't it? Node Debug 1.21.2 |
@wywywywy yes, node-debug is builtin but you can override it if you have another version in your extensions folder. And you are not seeing any Node Debug extensions under "Show Installed Extensions"? |
That's right. Only in show built-in. By the way I have tested this on 2 PCs (both Win 10) and both behave the same. |
And you are seeing the debug console message "Debugging with inspector protocol because Node.js v8.9.1 was detected." on both PCs? |
Could you try the latest Insiders? |
Just tried it with the Insiders. Same.
|
Do you actually see the node.js child processes in Windows Task Manager? |
Could you try this code (which works fine for me on all platforms): const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
console.log(`Master ${process.pid} is running`);
// Fork workers.
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`);
});
} else {
// Workers can share any TCP connection
// In this case it is an HTTP server
http.createServer((req, res) => {
res.writeHead(200);
res.end('hello world\n');
}).listen(8000);
console.log(`Worker ${process.pid} started`);
} |
Yes this is already the code I am using, from your test plan. And this is the launch.json for the test plan code.
|
And do you see the node.js child processes in Windows Task Manager? |
Yes that is correct. Also if I just run the test.js in console without debug I do see the "worker xxx started" messages, so the code runs fine. I just don't understand why the debugger won't attach. |
Please show screenshots! It is very difficult for me to understand what is going on without having the full picture. |
Could you please configure your Task Manager to show the command line arguments (see http://www.winhelponline.com/blog/configure-task-manager-to-display-full-path-of-running-processes/) and add a screenshot of the child processes and their arguments. This is what I am seeing: |
No, if you compare the node.js arguments in our screenshot, there is no difference. But you have way more child processes. Please try to limit the number to 4 and see whether this makes a difference. |
Just tried and max 4 has not made a difference. |
Thanks for trying! |
So this morning I tried it on my office PC, and without any change to the code, it started working! The only change is a reboot. I agree that it's gotta be something to do with "wmic process get CommandLine,ParentProcessId,ProcessId", which I will try on my other PC when I get home. My hunch is that perhaps another program has "--debug-port" in its command line. But I will be able to confirm later today. I think that if these lines below were changed to have the word "node" in it, or even better the filename of the JS file being executed, it will make the process more reliable.
|
In addition I've tried to understand what is going on in your first screenshot of #45320 (comment). There is an active debug session but no stack trace and no indication that the program is stopped. In addition I see an error squiggly for argument "signal". When I do the same on Windows I see this: Are you able to stop on the breakpoint on the line with the "cluster.fork()"? |
I'm glad that you found the issue. I should have suggested a reboot earlier, but since I'm a macOS user, a reboot never comes to my mind... We do not match on "node" because we want to allow debugging of node-like programs that do not use the word "node" in their executable name. I'm currently looking into a replacement for the 'wmic'. May be that helps to avoid the problem you had. |
Wait please don't close this yet! I am still having the same problem with one of the PCs. I have of course rebooted. And I check To answer your question, when stopped at a breakpoint, it does show the call stack and everything. When I press F5 the call stack and everything else disappears. |
You'll be pleased to know that I've found the real reason!!!! 💃 🍡 🗡
The buffer is set to 1000*1024, but my wmic output is much bigger than that, mainly consumed by blank spaces (services I guess?) and Chrome and Firefox. Hence the code wasn't able to find the node processes. My suggestions as a fix -
Is this reasonable? |
Great find! Thanks a lot for your continued investigation. This probably explains why a reboot helped: after the reboot the number of processes was small enough to fit in the 1 MB buffer. Yes, the output of wmic is horrible: if there is a single long entry all other entries are padded with spaces to the same width. Yes, your suggestions make sense and as I said previously are in line with my plan to replace 'wmic' by using a native library on Windows. |
As a first step I've eliminated the fixed size buffer. Please give it a try in the next Insiders build. |
Nice that library sounds just perfect for the job! And yes sure I will give it a try in a couple of days and report back. Many thanks for your help. |
I am currently on the latest Insiders build, but it does not seem to work. I am not familiar with Insiders, do I need to update Node Debug manually/separately? The built-in Node Debug (Legacy) is version 1.22.1.
|
The fix will be in node-debug 1.22.2 which will be part of tomorrow's Insiders. There is nothing special about the Insiders build. No need to update node-debug explicitly. |
Hello. I'm here to report that it works great 🔫😁🔫 Thank you very much for your help. Usually how long does it take for a feature in Insiders to go into the main branch? |
Basically I am having trouble attaching the VS Code debugger to the subprocesses I have in my Node app. It only attaches to the master process.
I have already read and followed the official documentation here - https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_automatically-attach-debugger-to-nodejs-subprocesses
My Node code uses the cluster module to fork a few worker. Pretty standard really and it follows the cluster example code.
And my launch.json already has autoAttachChildProcesses defined.
But the child processes don't show up in the call stack or the floating debugger control, unlike the official documentation. The debugger console doesn't say anything about the child processes either. And of course breakpoints set in the child process (the
startClusterWorkers()
function above) don't work.Any ideas what I am doing wrong please?
VS Code ver 1.20.1 & 1.21.0 (latest)
Node ver 8.9.1
The text was updated successfully, but these errors were encountered: