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

Debugger doesn't work for processes which fork other processes #9435

Closed
medikoo opened this issue Nov 3, 2016 · 38 comments
Closed

Debugger doesn't work for processes which fork other processes #9435

medikoo opened this issue Nov 3, 2016 · 38 comments
Labels
child_process Issues and PRs related to the child_process subsystem. feature request Issues that request new features to be added to Node.js. inspector Issues and PRs related to the V8 inspector protocol stale

Comments

@medikoo
Copy link

medikoo commented Nov 3, 2016

I'm running:

$ node --inspect some-node-script.js

Where some-node-script.js uses plain child_process.fork (run with defaults mostly) calls to initialize few other processes internally. Right after that I receive message Unable to open devtools socket: address already in use:

$ node -v
v7.0.0
$ node --inspect some-node-script.js
Debugger listening on port 9229.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:
    chrome-devtools://devtools/remote/serve_file/@60cd6e859b9f557d2312f5bf532f6aec5f284980/inspector.html?experiments=true&v8only=true&ws=localhost:9229/edbce9e9-0a9d-4c24-8f2b-bcaaeb4a5965
Unable to open devtools socket: address already in use

Also forked process crashes so technically application doesn't run (I've skipped that part of a log to avoid not related noise).

Behavior is same in both latest Node.js v7 and v6 (Tested on OSX, both El Captain and Sierra, with latest Chrome on board)

Am I doing something wrong, or there's no support currently for multi-process Node.js apps?

I've found similar issue which states that this probably should just work, but gives no clue why it actually doesn't.

I'll be happy to provide simple test case if needed

@mscdex mscdex added child_process Issues and PRs related to the child_process subsystem. debugger inspector Issues and PRs related to the V8 inspector protocol and removed debugger labels Nov 3, 2016
@mscdex
Copy link
Contributor

mscdex commented Nov 3, 2016

/cc @nodejs/v8-inspector

@bnoordhuis
Copy link
Member

I've found similar issue which states that this probably should just work, but gives no clue why it actually doesn't.

child_process.fork() doesn't fix up execArgv, only cluster.fork() does. See #8495 (comment).

@medikoo
Copy link
Author

medikoo commented Nov 3, 2016

child_process.fork() doesn't fix up execArgv, only cluster.fork() does. See #8495 (comment).

Thanks, that clearer now. Is there a plan to fix it for child_process.fork?

@medikoo
Copy link
Author

medikoo commented Nov 3, 2016

After reading this comment I see that probably #5025 is meant to fix this issue

@bmeck
Copy link
Member

bmeck commented Nov 17, 2016

with v8 landing RemoteExecutionContext, it should be possible for a debugger to work for multiple processes. I don't know if we are ready for that and it requires v8 version >=55 which isn't going to land on Node v6

@eugeneo
Copy link
Contributor

eugeneo commented Nov 17, 2016

V8 inspector protocol has support for the "subtargets" - we are currently
looking into leveraging that for the node processes that fork children.
#9630 updates the HTTP transport for the
inspector, now it should be able to track multiple "sessions" and also list
multiple targets.

Currently we are considering introducing a special "inspector" pipe from
the parent to a child so the child does not have to run the HTTP server.
All communications with the children will happen through the parent, parent
will also be able to list individual children.

Note that this work is in experimental stage and the design will likely
change a lot.

On Thu, Nov 17, 2016 at 1:21 PM Bradley Meck [email protected]
wrote:

with v8 landing RemoteExecutionContext, it should be possible for a
debugger to work for multiple processes. I don't know if we are ready for
that and it requires v8 version >=55 which isn't going to land on Node v6


You are receiving this because you are on a team that was mentioned.

Reply to this email directly, view it on GitHub
#9435 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AARkrb9lYhslDNRD2jh8KnSe5jJ03pspks5q_MVegaJpZM4KoFlU
.

@Trott
Copy link
Member

Trott commented Jul 15, 2017

@eugeneo Should this remain open?

@eugeneo
Copy link
Contributor

eugeneo commented Jul 17, 2017

I believe it can be closed.

@eugeneo eugeneo closed this as completed Jul 17, 2017
@medikoo
Copy link
Author

medikoo commented Jul 17, 2017

Does it mean, there's no plan to fix it?

Multi-process Node.js configurations are not that uncommon, and currently debugger functionality is not usable having such setup. I see it as quite important issue.

@Trott
Copy link
Member

Trott commented Jul 18, 2017

/ping @bnoordhuis Is the reasoning in #8495 (comment) basically an explanation of why the behavior observed here is the way it is, and why it is unlikely to be changed?

@medikoo Does it work in Node.js 8.x if you invoke the script like this?:

$ node --inspect --inspect-port=0 some-node-script.js

@bnoordhuis
Copy link
Member

I'm not mordicus against changing child_process.fork() to be more like cluster.fork(), symmetry is good, but I do think there is a non-zero change it will break third-party code.

@medikoo
Copy link
Author

medikoo commented Aug 16, 2017

Any chance to have that reopened?

@refack
Copy link
Contributor

refack commented Aug 16, 2017

@medikoo AFAIK GitHub should let you reopen issues you submitted, but in anyway, @eugeneo has set a goal to implement multiplexing multiple inspector "channels" into a single socket connection. This will allow subprocesses to be "inspected" through their parent's socket.

Also as mentioned before, in [email protected] it's possible to use arbitrary port binding for inspector with:
node --inspect=0 some-node-script.js
you only need to watch the output messages for information on which ports were allocated.
You could also pass an explicit port in execArgv for cp.fork(), similar to what cluster.fork() does:

} else {
inspectPort = process.debugPort + debugPortOffset;
debugPortOffset++;
}

@medikoo
Copy link
Author

medikoo commented Aug 16, 2017

@medikoo AFAIK GitHub should let you reopen issues you submitted

Only if it's me that closed it. Here it's not the case, I'm not able to reopen it.

@Freundschaft
Copy link

Im having this issue now using a library that forks processes, where I have no influence on how the child processes are called. As soon as I use debugging mode, it screws up. Is there an open issue somewhere if we cant reopen this one?

@FedericoBiccheddu
Copy link

Hi to all, there is a workaround for this?

Working locally with nodemon (and docker just fyi) debugging is not possible, even using NODE_OPTIONS.

Screenshot example

@bmeck
Copy link
Member

bmeck commented Jun 22, 2018

There is a terrible workaround I use:

> NODE_OPTIONS=`--inspect-port=0`

And then use the terminal output to put into chrome:inspect manually.

screen shot 2018-06-22 at 9 11 58 am

@FedericoBiccheddu
Copy link

Hi @bmeck, thank you for the response.

An ephemeral port is not portable and configurable so, unfortunately, is not a solution because I should update the port in the IDE's config everytime.

PS: I don't think Chrome is suitable for a server side project debugging session 😞

@vith
Copy link

vith commented Jun 22, 2018

@FedericoBiccheddu in a pinch you should be able to use SSH port forwarding to connect your local chrome to a remote (localhost) debug port. I believe with openssh it's -L <local_port:remote_addr:remote_port> where remote_addr is from the perspective of the ssh server you're connecting to. So 127.0.0.1 as remote_addr can forward the connection to the remote server's localhost ports.

@FedericoBiccheddu
Copy link

Hi @vith, thank you for the response.

As I said in the previous comment unfortunately is not a solution. Being more specific:

  1. Some team members use only Firefox
  2. It's a server side application (I don't think Chrome is the right tool to debug a server side application)
  3. The debugger is integrated in the IDE (WebStorm or VSCode)
  4. Using docker where the app has multiple services (not docker-machine)
  5. Front-end and back-end team should work with the same code base; we need to have a portable and maintanable solution
  6. openssh is a third-party program

I think the workaround should be limited on the node or docker side.

@sergiybuch
Copy link

"terrible" workaround is not helping me. I am trying to debug Protractor tests, using Webstorm.

@bmeck
Copy link
Member

bmeck commented Jul 2, 2018

I've opened https://groups.google.com/forum/#!forum/google-chrome-developer-tools to start discussion on things, but all these non-chrome approaches such as IDEs would need to adopt any solution that would be agreed upon if the feature is seen as safe/valuable enough to implement.

@eason-shsf
Copy link

this problem still exists on node 8.11.3, is there a plan for fixing this?

@CFKevinRef
Copy link

@bmeck
Copy link
Member

bmeck commented Jul 30, 2018

@CFKevinRef yes, but it looks like Google is working on https://github.com/GoogleChromeLabs/ndb (recently made public) which should supercede that

@CADBOT
Copy link

CADBOT commented Aug 21, 2018

Even if it works in ndb, it would be great to have in the command line debugger. I'm a huge fan of it as it involves less context switching.

@trusktr
Copy link
Contributor

trusktr commented Sep 4, 2018

I'm sure once it's fleshed out it will find its way in. But prepending ndb to any command is so easy!👍

@mdrichardson
Copy link

@ilijaz Thanks!

const options = {
  execArgv: []
};
const child = Child.fork(program, options);

Although not an ideal fix, this was a great workaround.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2022

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot added the stale label Mar 4, 2022
@targos targos moved this from Pending Triage to Stale in Node.js feature requests Mar 6, 2022
@targos targos moved this to Pending Triage in Node.js feature requests Mar 6, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Apr 4, 2022

There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

For more information on how the project manages feature requests, please consult the feature request management document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. feature request Issues that request new features to be added to Node.js. inspector Issues and PRs related to the V8 inspector protocol stale
Projects
None yet
Development

No branches or pull requests