Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Specify debug port per worker #5318

Closed
pavele opened this issue Apr 17, 2013 · 9 comments
Closed

Specify debug port per worker #5318

pavele opened this issue Apr 17, 2013 · 9 comments

Comments

@pavele
Copy link

pavele commented Apr 17, 2013

Hi,
Currently it looks impossible to debug worker processes. Here is a discussion related with node-inspector:
node-inspector/node-inspector#130

Is it possible to add ability to change the debug ports for the workers?

Thanks

@IvanTorresEdge
Copy link

I was also following issue #130 and none of the alternatives posted there works for us. Kind of frustrated around this, so +10

@chestone
Copy link

Having the same issue here and it is frustrating.

@bnoordhuis
Copy link
Member

We'll address that in due time. The cluster module is scheduled for rework anyway. Until then, you can use something like this:

var cluster = require('cluster');
var http = require('http');

if (cluster.isMaster) {
  var debug = process.execArgv.indexOf('--debug') !== -1;
  cluster.setupMaster({
    execArgv: process.execArgv.filter(function(s) { return s !== '--debug' })
  });
  for (var i = 0; i < 2; ++i) {
    if (debug) cluster.settings.execArgv.push('--debug=' + (5859 + i));
    cluster.fork();
    if (debug) cluster.settings.execArgv.pop();
  }
}
else {
  var server = http.createServer(function(req, res) {
    res.end('OK');
  });
  server.listen(8000);
}

It's improper use of the API (cluster.settings should be considered immutable) but this snippet works with v0.10.

@ghost ghost assigned bnoordhuis Apr 20, 2013
tico8 added a commit to tico8/node that referenced this issue Aug 8, 2013
Implement support for debugging cluster workers. Each worker process
is assigned a new debug port in an increasing sequence.

I.e. when master process uses port 5858, then worker 1 uses port 5859,
worker 2 uses port 5860, and so on.

Introduce new command-line parameter '--debug-port=' which sets debug_port
but does not start debugger. This option works for all node processes, it
is not specific to cluster workers.

Fixes nodejs#5318.
(cherry picked from commit 43ec1b1)

Conflicts:

	src/node.cc
tico8 pushed a commit to tico8/node that referenced this issue Oct 24, 2013
Implement support for debugging cluster workers. Each worker process
is assigned a new debug port in an increasing sequence.

I.e. when master process uses port 5858, then worker 1 uses port 5859,
worker 2 uses port 5860, and so on.

Introduce new command-line parameter '--debug-port=' which sets debug_port
but does not start debugger. This option works for all node processes, it
is not specific to cluster workers.

Fixes nodejs#5318.
justsee pushed a commit to socialally/node that referenced this issue Mar 17, 2014
Implement support for debugging cluster workers. Each worker process
is assigned a new debug port in an increasing sequence.

I.e. when master process uses port 5858, then worker 1 uses port 5859,
worker 2 uses port 5860, and so on.

Introduce new command-line parameter '--debug-port=' which sets debug_port
but does not start debugger. This option works for all node processes, it
is not specific to cluster workers.

Fixes nodejs#5318.

Conflicts:
	src/node.cc
@benfleis
Copy link

benfleis commented May 5, 2014

@bnoordhuis @bajtos Any plans to backport the proper to v0.10 (including the -port command line arg)?

@indutny
Copy link
Member

indutny commented May 5, 2014

@benfleis that would be a behavior change, I think. This could be done only in unstable branches.

@benfleis
Copy link

benfleis commented May 5, 2014

@indutny Makes sense. Thanks :)

@Redsandro
Copy link

I think a similar problem is happening when using child.fork() when the parent is already using --debug.

Failed to open socket on port 5858, waiting 1000 ms before retrying

I guess we can override this using arguments, but the documentation is not opening my eyes yet.

@Redsandro
Copy link

Workaround, something like this before you fork():

var debugArgIdx = process.execArgv.indexOf('--debug');
if (debugArgIdx !== -1) {
    // Remove debugging from forked process
    process.execArgv.splice(debugArgIdx, 1);
}

@srlowe
Copy link

srlowe commented Nov 6, 2014

In which version is this working properly?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants