-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Support auto attach for node.js subprocesses (aka cluster support) #40123
Comments
This is cool. Here's an issue from someone debugging with the cluster module: #39033 How does |
@roblourens yes, cluster increments port numbers like this (from the Process Viewer): "inspect" by using an interesting "inspect-port" flag: If a port is specified, "inspect-port" overrides the "inspect" port: |
Finally! Looks like a nice feature. Does it have any downsides or would this feature be enabled by default? |
"autoAttachChildren" is an idiotic attribute name. |
I don't think it's that bad. That's exactly what it does. I can only think of some variations on it like |
The generated config maybe should copy outFiles and other props from the original config. |
I agree with rob, for me the name of this setting tells what it is supposed to do. I prefer childProcess over children though. |
Then let's go with "autoAttachChildProcesses" (yes, it's long but we have IntelliSense...) |
…in the launch config, for microsoft/vscode#40123
This is great - it should be built into VS Code. Anyone who wants to debug a parent and its child processes in Node wants this. |
A first cut is already in VS Code Insiders. |
@roblourens I've verified (by patching Insiders) that your fix would work fine. |
I just press cmd+shift+b :) What problem did you have? I just published 1.20.0. |
|
It works for me |
No, but I just cleaned everything and I see the same thing. Something wrong with my package-lock.json? |
If I delete and regenerate the package-lock, there are a million changes and |
The last few times I've done something that changes the package-lock.json, I've seen it randomly add and remove those |
This feature works now in Insiders. Try this sample: 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`);
} with this launch config: {
"type": "node",
"request": "launch",
"name": "Cluster",
"program": "${workspaceFolder}/test.js",
"autoAttachChildProcesses": true
}, |
Hello @weinand I can't set up http server on each cluster according with your code.
Output data:
May be you can clarify why cluster.fork() command doesn't achieve next parts of script. |
@ddorkin-issart How does your launch config look like? |
@weinand This is excellent when using npm, but is there anything special that needs to be done to incorporate nodemon on a cluster? |
@mdhornet90 this feature has nothing to do with npm.
|
Alright, so this feature is independent of how node is started, thanks for the insight! |
While working on the Process viewer, I noticed that we could easily support node.js "Clusters" (or any other spawned processes) with a similar approach.
Here is a sketch:
The result looks like this (and a first cut will be available in the next Insiders).
I've verified the feature (for macOS only) with the example from the node.js documentation for 'cluster':
Here is the launch config:
This already works fine for node.js < v8 (legacy).
For node.js >= v8 the problem is that all workers stop on entry, which requires some manual "continuing". The problem is that node-debug2 does not automatically send a "continue" request because it guesses that a "stop on entry" is desired. Node-debug1 had the same problem but I made it "guess" better in this case...
The work around for node.js >= v8 uses an explicit "--inspect" instead of "--inspect-brk":
The fix for node-debug was to only set
this._stopOnEntry
if it hasn't been set in the launch config:see https://github.com/Microsoft/vscode-node-debug/blob/9a9ccb1703741fbad10e29d1769c0b8fc5cd3228/src/node/nodeDebug.ts#L1517
/cc @roblourens @auchenberg @isidorn
The text was updated successfully, but these errors were encountered: