You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
can --inspect be made to bind debug ports for child processes too? #459
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:
Another note, this does behave properly when using node directly, like so:
git clone https://github.com/AndrewJDR/inspect-on-forked-processes-doesnt-work
cd inspect-on-forked-processes-doesnt-work
npm i
tsc
cd dist
node --inspect index.js
produces:
Debugger listening on ws://127.0.0.1:9229/3ceeb68c-e9a0-481e-b69d-961c640dfd51
For help see https://nodejs.org/en/docs/inspector
launching child
Debugger listening on ws://127.0.0.1:9230/cf548fe0-7358-469d-af91-405eb886bafc
For help see https://nodejs.org/en/docs/inspector
in the parent: 16502
in the child: 16510
Which already looks better, since we have two "Debugger listening on..." messages instead of just the one I see with ts-node. Just to be sure, I confirmed via netstat that both ports are bound, and they are. So this seems like a ts-node issue, not a node issue.
to join(__dirname, 'bin.js') fixes this? The result would basically be having the child process spawn a child node.js process the same way ts-node does.
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.
That's interesting, thanks! It seems to be a tiny bit closer but not enough. Final test, can you try with node -r ts-node/register --inspect index.ts? If that works, I might refactor how ts-node is spawning the child node process - without any investigation it appears node.js might be doing some internal management for --inspect child spawning and changing the executable is breaking that management.
Awesome news! I'm not sure when I'll get around to hitting this, but I have a decent idea of how I may approach fixing it now. Basically, I'm going to need to refactor to use that command style of spawned command instead and remove the current approach used except in the case of opening the REPL. Thanks for your debugging of the issue 😄
FWIW #476 would allow you to start inspect only on the child process.
Indeed, Node itself does quite a few things for managing ports, and that behavior might be a tad bit different depending on the version of Node you are using. The only safe and sound thing to do would either to capture flags in a non-node process, pass them to bin.ts and let it figure out how to set flags on _bin.ts, or getting rid of the child process tree overall (which would actually solve quite a few problem from what I can see).
I would love to kill the process tree at this point. The main reason it's required is actually for REPL support, but I think it'd be good and/or fine to move toward ts-node for REPL only and node -r ts-node for everything else, or at the very least detect if it looks like REPL or regular usage and switch behaviour to prefix --require ts-node/register.
You're right, we do need to proxy through the flags if we expose an executable ts-node. However, I think it could be done by instead prefixing -r ts-node/register before spawning the child (it seems it would fix this issue). Even better might be just to kill this feature to recommend node -r ts-node/register though - I'm not sure how many people prefer ts-node script.ts over node -r ts-node/register script.ts. I'd guess it's non-trivial, but I think it's a more stable pattern with no need to mess with child processes.
Activity
AndrewJDR commentedon Nov 9, 2017
Another note, this does behave properly when using node directly, like so:
produces:
Which already looks better, since we have two "Debugger listening on..." messages instead of just the one I see with ts-node. Just to be sure, I confirmed via netstat that both ports are bound, and they are. So this seems like a ts-node issue, not a node issue.
blakeembrey commentedon Nov 15, 2017
That's interesting.
ts-nodejust starts an underlying node.js process by spawning_bin.js. Can you check if changing__filenameints-node/src/_bin.ts
Line 176 in 1d630f9
join(__dirname, 'bin.js')fixes this? The result would basically be having the child process spawn a child node.js process the same wayts-nodedoes.AndrewJDR commentedon 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:Basically it seems the child tries to bind to the same port as the parent.
blakeembrey commentedon Nov 16, 2017
That's interesting, thanks! It seems to be a tiny bit closer but not enough. Final test, can you try with
node -r ts-node/register --inspect index.ts? If that works, I might refactor howts-nodeis spawning the child node process - without any investigation it appears node.js might be doing some internal management for--inspectchild spawning and changing the executable is breaking that management.AndrewJDR commentedon Nov 16, 2017
@blakeembrey Yep,
node -r ts-node/register --inspect index.tsworks! Both ports are bound just fine using that command.blakeembrey commentedon Nov 19, 2017
Awesome news! I'm not sure when I'll get around to hitting this, but I have a decent idea of how I may approach fixing it now. Basically, I'm going to need to refactor to use that command style of spawned command instead and remove the current approach used except in the case of opening the REPL. Thanks for your debugging of the issue 😄
stelcheck commentedon Dec 10, 2017
FWIW #476 would allow you to start inspect only on the child process.
Indeed, Node itself does quite a few things for managing ports, and that behavior might be a tad bit different depending on the version of Node you are using. The only safe and sound thing to do would either to capture flags in a non-node process, pass them to
bin.tsand let it figure out how to set flags on_bin.ts, or getting rid of the child process tree overall (which would actually solve quite a few problem from what I can see).ORESoftware commentedon Dec 10, 2017
This issue is related #471
I get the same error (address already in use)
blakeembrey commentedon Dec 10, 2017
I would love to kill the process tree at this point. The main reason it's required is actually for REPL support, but I think it'd be good and/or fine to move toward
ts-nodefor REPL only andnode -r ts-nodefor everything else, or at the very least detect if it looks like REPL or regular usage and switch behaviour to prefix--require ts-node/register.stelcheck commentedon Dec 12, 2017
Oh, I was under the impression it was because of v8 flags and general flag parsing/mangling?
blakeembrey commentedon Dec 12, 2017
You're right, we do need to proxy through the flags if we expose an executable
ts-node. However, I think it could be done by instead prefixing-r ts-node/registerbefore spawning the child (it seems it would fix this issue). Even better might be just to kill this feature to recommendnode -r ts-node/registerthough - I'm not sure how many people preferts-node script.tsovernode -r ts-node/register script.ts. I'd guess it's non-trivial, but I think it's a more stable pattern with no need to mess with child processes.stelcheck commentedon Dec 20, 2017
#499 Would solve this issue.
blakeembrey commentedon Feb 19, 2018
The
ts-nodesubprocess has been killed with #536.