node-inspector: When using cluster, node-inspector cannot debug child (forked) processes

The cluster (http://nodejs.org/api/cluster.html) node feature spawn child processes, normally one per CPU. Without using cluster, node-inspector works like a charm; however, with cluster, node-inspector doesn’t allow debugging of child processes’ code. In the example below, if you put a breakpoint at the “for” statement and another one at the “var app” statement, you will see that only the “for” one breaks. If there are files being require()d for the child processes (as almost always is the case), node-inspector will not list those files.

If cannot be fixed, probably worth mentioning in the Known Issues section of the md (I don’t mind adding this).

Example:

var express = require('express');
var cluster = require('cluster');
var numCPUs = require('os').cpus().length; // Get the number of CPUs
if (cluster.isMaster) {
    // Fork each worker onto its own thread
    for (var i = 0; i < numCPUs; i++) {
        var worker = cluster.fork();
        console.log("Launched a new worker with PID=", { pid: worker.pid });
    }
} else {
    var app = express.createServer();
    console.log("server listening on port 8090");
    app.listen(8090);
}

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 15 (3 by maintainers)

Most upvoted comments

@chi-e You have to put that line in the source code of your child process.

Example:

// child.js
var cluster = require('cluster');
process._debugPort = 5858 + cluster.worker.id

// the rest of the code running in the child process

I’ve been having the same problem, nice to see I’m not alone here.