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

Node child forks can't use the debugger #19

Closed
romainbessugesmeusy opened this issue Feb 13, 2017 · 8 comments
Closed

Node child forks can't use the debugger #19

romainbessugesmeusy opened this issue Feb 13, 2017 · 8 comments

Comments

@romainbessugesmeusy
Copy link

Hi Jos,

It looks like I can't use node debugger while spawning child processes, because each worker try to use the same port. Example:

Debugger listening on 127.0.0.1:51884
Error: listen EADDRINUSE 127.0.0.1:51884
    at Object.exports._errnoException (util.js:1023:11)
    at exports._exceptionWithHostPort (util.js:1046:20)
    at Agent.Server._listen2 (net.js:1261:14)
    at listen (net.js:1297:10)
    at doListening (net.js:1396:7)
    at _combinedTickCallback (internal/process/next_tick.js:77:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

It seems that child forks have to be created with the --debugger={port}. My first guess would be to change this line (WorkerHandler.js:79):

    this.worker = node.require('child_process').fork(this.script);

What do you think?

Thanks again for your work, cheers from France

@romainbessugesmeusy
Copy link
Author

I think it's interesting to mention this discussion on the IntelliJ / WebStorm board

https://intellij-support.jetbrains.com/hc/en-us/community/posts/206193339-Debugging-node-child-processes

@josdejong
Copy link
Owner

Thanks for reporting Romain!

It seems that child forks have to be created with the --debugger={port}

Wouldn't that always run the childs in debug mode, also if you just want to run in production?

@romainbessugesmeusy
Copy link
Author

Yeah I fear you're right. Furthermore I haven't found yet how to attach a remote debugger to child process inside Webstorm... Maybe this could be passed when creating the pool, as a secondary argument.

var workerpool = require('workerpool');

// create a worker pool using an external worker script
var pool = workerpool.pool(__dirname + '/myWorker.js', {
   node: {
       childProcessExecArgs: (childIndex) => return '--debugger=' + (53027 + childIndex)
   }
});

@josdejong
Copy link
Owner

hm that's odd. I can hardly believe we're the first stumbling upon this problem.

Maybe we could check whether the --debugger option is in the arguments of the main process, and only then add it in the childProcessExecArgs with a unique port. Or is that what you mean?

From the thead you mentioned I understand that it should be enough to pass an argument --debug-brk which will let node.js automatically pick a free port.

Oh, it could be simplified in the following way (forgot to mention it in the first place):

var childProc= fork('./public/LG/lg.js',{execArgv: ['--debug-brk']})

In that case node automatically finds a free port.

@romainbessugesmeusy would you be interested in doing some experimenting with this to find a working solution for workerpool?

@romainbessugesmeusy
Copy link
Author

Yeah I'll look into that 👌

@josdejong
Copy link
Owner

👍

@josdejong
Copy link
Owner

@romainbessugesmeusy did you already found some time to look into the debugging issue?

@josdejong
Copy link
Owner

This issue should have been fixed now in v2.2.1 (see #21)

maybephilipp pushed a commit to maybephilipp/workerpool that referenced this issue Sep 27, 2020
* Add scenario

* extra spaces

* expand uploadFile for specify different files

* change action for use fieName

* too early try to upload file

* trying to fix login unstability

Co-authored-by: Aleksey Gerasimov <[email protected]>
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