question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

can --inspect be made to bind debug ports for child processes too?

See original GitHub issue

repro steps (I did this on linux and bash):

git clone https://github.com/AndrewJDR/inspect-on-forked-processes-doesnt-work
cd inspect-on-forked-processes-doesnt-work
npm i
npm start

This starts a child process using cluster.fork(). Note that debugger listens fine on the master process:

Debugger listening on ws://127.0.0.1:9229/1ffaac86-3b3f-4097-aa90-df1eba66b6f4
launching child
in the parent: 13039
in the child: 13049

And checking netstat shows that 9229 is indeed bound, which is good.

$ netstat -lnp | grep 9229
tcp        0      0 127.0.0.1:9229          0.0.0.0:*               LISTEN      13039/node      

However, no debugging port is bound for the child process. The output of ps, the --inspect-port=9230 argument would lead one to believe that a debugger port 9230 is available for the child process:

$ ps aux | grep ts-node
13027 pts/30   S+     0:00 sh -c ts-node --inspect -F index.ts
13028 pts/30   Sl+    0:00 node ~/Documents/src/inspect-on-forked-processes-doesnt-work/node_modules/.bin/ts-node --inspect -F index.ts
13039 pts/30   Sl+    0:00 ~/.nvm/versions/node/v9.0.0/bin/node --inspect ~/Documents/src/inspect-on-forked-processes-doesnt-work/node_modules/ts-node/dist/_bin.js -F index.ts
13049 pts/30   Sl+    0:00 ~/.nvm/versions/node/v9.0.0/bin/node ~/Documents/src/inspect-on-forked-processes-doesnt-work/node_modules/ts-node/dist/_bin.js --inspect --inspect-port=9230 ~/Documents/src/inspect-on-forked-processes-doesnt-work/index.ts

However, this is unfortunately not the case, looking at netstat output:

$ netstat -lnp | grep 9230
(.. nothing to see here ..)

Can others reproduce this? If so, can this please be addressed so that we can debug child processes properly?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
AndrewJDRcommented, Nov 15, 2017

I tried process.execArgv.unshift(require('path').join(__dirname, 'bin.js')); and it didn’t work. This is the error I get:

 $ npm start

> inspect-on-forked-processes-doesnt-work@1.0.0 start ~/Documents/src/inspect-on-forked-processes-doesnt-work
> ts-node --inspect index.ts

Debugger listening on ws://127.0.0.1:9229/ed2df97b-b3cd-4f42-a422-16bf231cecd2
For help see https://nodejs.org/en/docs/inspector
launching child
Starting inspector on 127.0.0.1:9229 failed: address already in use
in the parent: 15237

Basically it seems the child tries to bind to the same port as the parent.

0reactions
blakeembreycommented, Feb 19, 2018

The ts-node subprocess has been killed with https://github.com/TypeStrong/ts-node/pull/536.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to debug a child process in Node and Gatsby.js with ...
Running --inspect-brk enables the inspector agent to bind to default host 127.0.0.1 and listen on the default port 9229 . Since multiple debuggers...
Read more >
Impossible to debug node.js process that spawns child ...
What steps will reproduce the problem? 1. Have a node.js application/file that creates at least one child process - cp.fork('filepath') 2. Run with...
Read more >
Use Node.js command line debugger on child process?
Yes. You have to spawn your process in a new port. There is a workaround to debug with clusters, in the same way...
Read more >
How To Debug Node.js with the Built-In Debugger and ...
To solve this problem, developers use tools like a debugger, a program that allows developers to inspect their program as it runs. By...
Read more >
Debug Node.js Apps using Visual Studio Code
With this setting, the debugger can attach to an already running process that was not started in debug mode. When using the processId...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found