Repository navigation
Description
Environment:
- VS Code Version 0.10.9
- Mac OS 10.10.5
- Node.js v4.3.1
Steps to Reproduce:
Create a new directory named cluster-test
Create a new file cluster-test\app.js with sample code from https://nodejs.org/dist/latest-v4.x/docs/api/cluster.html#cluster_cluster as follows:
const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
// Fork workers.
for (var 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);
}
Open cluster-test in VS Code
Switch to the Debug view and click the Start icon, or press F5
Select "Node.js" as the debug environment
Click Start again
Point you browser to http://localhost:8000/
Observe that no one is listening
Exit VS code, open a command prompt and invoke:
node cluster-test\app.js
Point you browser to http://localhost:8000/
Observe that a "hello world" response is received
Conclusion:
Basic node cluster example fails in VS Code
Activity
weinand commentedon Feb 21, 2016
Curt Williams (@curtw) how does you launch config look like?
curtw commentedon Feb 21, 2016
My launch.json file is unaltered from that which VS Code created by default:
Benzeliden commentedon May 1, 2016
Reproduced for me in debug mode
But this example works when launching without debugging (ctrl + F5\ cmd + F5)
sunjunzero commentedon May 20, 2016
vscode default use --debug-brk to enable the debug support which block the child process at beginning.
enif-lee commentedon Jun 10, 2016
+1
In my case, not works when using sticky-cluster module, but using ctrl+F5 normally works ..T_T
weinand commentedon Jun 10, 2016
Yes, the
--debug-brkoption is the problem. Currently there is no way to prevent VS Code from using this option, but there are two workarounds:change the argument by adding this statement as the first line to
app.js:or launch node from a terminal and attach to it with the VS Code debugger.
Run in terminal:
Then select the default 'attach' launch config and attach to it.
The 2nd workaround is the preferred way if you actually want to debug any worker and not just the first process that is launched.
For the example from above you could add the debug port to the hello world message:
and then you can attach to that port with VS Code.
weinand commentedon Jun 10, 2016
BTW, in the latest VS Code Insider you can use the new process picker support to select the cluster worker that you want to debug. After starting the cluster app from a terminal:
run the 'Attach to Process' launch config and select a process:
sylvainlap commentedon Jul 7, 2016
what could be the workaround if I want to debug all workers in the same time ?
sylvainlap commentedon Jul 8, 2016
Andre Weinand (@weinand) When I launch a node js process that is clustered, and try to 'Attach to Process', I only have the master process in the list. How do you manage to have the master process, and all the forks in your list (your screenshot) ?
23 remaining items
jez9999 commentedon Nov 17, 2017
Isidor Nikolic (@isidorn) Huh? Why is this an extension candidate? Automatically attaching to the correct port for cluster child processes seems well within the remit of VS Code considering it comes with a debugger and multi-process debugging.
isidorn commentedon Nov 17, 2017
The extension candidate label was already present in this issue, I simply reapplied it.
I see the discussion seems lively so I can reopen the issue and Andre Weinand (@weinand) can decide on how to proceed
weeco commentedon Dec 7, 2017
Andre Weinand (@weinand) Any update? What's the plan for this?
weinand commentedon Dec 7, 2017
For another project I wrote an extension that tracks all child processes of VS Code (which could include a node.js cluster) and allows to pick node.js processes for debugging based on ports or pids.
This could be an alternative way of supporting a node.js cluster (alternative to the new Inspector Protocol target domain mentioned above).
weinand commentedon Dec 12, 2017
I followed my own suggestion: please see some progress in #40123
weinand commentedon Dec 21, 2017
duplicate of #40123.