简体   繁体   English

Node.js调试-无法附加调试器子进程

[英]Node.js debugging - cannot attach debugger subprocesses

Basically I am having trouble attaching the VS Code debugger to the subprocesses I have in my Node app. 基本上,我在将VS Code调试器附加到Node应用程序中的子进程时遇到了麻烦。 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 我已经在这里阅读并遵循了官方文档-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. 确实很标准,它遵循集群示例代码。

if (cluster.isMaster) {
    console.log(`Master process ${process.pid} starting...`);
    for (let i = 0; i < numCPUs && i < maxNumThreads; i++) {
        cluster.fork(); // Create a worker
    }
} else {
    startClusterWorkers();
}

function startClusterWorkers() {
    // xxxxxx
}

And my launch.json already has autoAttachChildProcesses defined. 我的launch.json已经定义了autoAttachChildProcesses。

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch app.js",
            "program": "${workspaceFolder}\\app.js",
            "restart": true,
            "autoAttachChildProcesses": true,
            // "console": "integratedTerminal"
        },
        {
            "type": "node",
            "request": "launch",
            "name": "Launch test.js",
            "program": "${workspaceFolder}\\test.js"
        }
    ]
}

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. 当然,在子进程中设置的断点startClusterWorkers()上面的startClusterWorkers()函数)不起作用。

Debugging with inspector protocol because Node.js v8.9.1 was detected.
node --inspect-brk=31761 app.js 
Debugger listening on ws://127.0.0.1:31761/54919117-38ae-4455-82c6-e21ade314bdd
Master process 10096 starting...

Any ideas what I am doing wrong please? 有什么想法我做错了吗?

VS Code ver 1.20.1 (latest) Node ver 8.9.1 VS Code版本1.20.1(最新)节点版本8.9.1

This turns out to be a bug - 原来是个错误-

https://github.com/Microsoft/vscode/issues/45320 https://github.com/Microsoft/vscode/issues/45320

It's fixed in Insiders now and should be in stable soon. 现在已在Insiders中修复,应该很快会稳定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM