Skip to content
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

Improve debugger for multi-threaded applications #180

Open
paulvi opened this issue Nov 17, 2014 · 4 comments
Open

Improve debugger for multi-threaded applications #180

paulvi opened this issue Nov 17, 2014 · 4 comments

Comments

@paulvi
Copy link
Member

paulvi commented Nov 17, 2014

Started as http://nodeclipse.uservoice.com/forums/216804-general/suggestions/4306388-improve-debugger-for-multi-threaded-applications by Andrew and P.

nodejs/node-v0.x-archive#5318 is labeled for Node 0.12 Milestone

@paulvi paulvi added the node.js label Nov 17, 2014
@p-bakker
Copy link

As asked on UserVoice, here's the info I have on the topic.

I want to debug a node application that uses multiple processes (through cluster). Trying this in Nodeclipse failed however.

First thing that failed was that the node app wouldn't launch properly at all when using the debug-brk options. Once that was disabled (by checking the option "run Node debug without -brk), the app can be started in debug mode, but breakpoints are never hit in the code that runs in a non-master process.

I googled and found this: https://youtrack.jetbrains.com/issue/WEB-1919. This link basically describes that in Node 0.11.x support was added to connect a debugger to forked processes, by automagically assign an incremental debug port to every forked process, while writing the debug port number out to STDERR of the master process, like "Debugger listening on port 58xx".

I see those messages showing up in the console in Nodeclipse as well.

However, Nodeclipse only launches one debug process, by default on port 5858, so it is quite logical that breakpoints aren't hit when the code is executed in another process that uses another debug port.

So, what I think needs to happen is that Nodeclipse monitors the STDERR for the messages "Debugger listening on port 58xx" and then automatically launches debug processes for these ports.

I tried to manually add and launch STANDALONE_V8 debug processes with the portnumbers that node assigns to the child processes and then breakpoints get hit.

So AFAICS it is a matter of listening to the STDERR for the port number messages, automatically launching a STANDALONE_V8 debugger on that port and making sure that these get killed/cleaned up propertly when terminating the main debug process or when one of the forked processes dies.

@paulvi
Copy link
Member Author

paulvi commented Nov 18, 2014

Hi Paul. That is great research already.

Logically, every process (of event looper) should have own port.

https://youtrack.jetbrains.com/issue/WEB-1919 says, that since Node 0.11.5 every fork would get own port incrementally from base specified as

node –debug-brk=50093 limsSrv.js
debugger listening on port 50093
debugger listening on port 50094
debugger listening on port 50095

nodejs/node-v0.x-archive@43ec1b1

tagged as v0.11.14, Fixes nodejs/node-v0.x-archive#5318

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.

For Node users before 0.11.5 ever forked process should get debug port manually

I guess, using --debug=58xx (without -brk)

  • Script example is needed.

@p-bakker Is that right?

Now, back to Nodeclipse, I would try to first launch Debug session for master with Nodeclipse,
then follow https://github.com/joyent/node/wiki/Using-Eclipse-as-Node-Applications-Debugger old way to set up Launch configurations like for remote debugging.
Note that Nodeclipse already comes with modified chromedevtools 0.3.9 (skip Installation section)

I expect it should work for several debug session at the same time, though I never tried.

Currently this is not on my list to go far with this,
but I will collaborate. Please share Node.js script sample that we can use to try.

@paulvi
Copy link
Member Author

paulvi commented Nov 28, 2014

@p-bakker Please keep this thread updated

@p-bakker
Copy link

p-bakker commented Dec 1, 2014

Still looking into this one, unfortunately wasn't able to spend much time on it. I'll report back later this week

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

No branches or pull requests

2 participants