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

--inspect should automatically get a new port if default port 9229 is already in use #28457

Closed
gustavomassa opened this issue Jun 27, 2019 · 6 comments

Comments

@gustavomassa
Copy link

image

Is your feature request related to a problem? Please describe.
Image a kubernetes cluster using minikube with 50 micro-services on a dev environment, each micro-service is launched using the --inspect param, so we can remotely debug the services, like using vs-code kubernetes extension. In that case, just using --inspect or --inspect-brk will try to use the same inspector port 9229 for each micro-service, resulting on startup errors and services not running at all.
image

Describe the solution you'd like
--inspect and --inspect-brk should try the default port 9229, if the port is already in use, automatically get a random port that is not in use, or just increment the current port number until the port is available.

Describe alternatives you've considered
Manually setting an unique inspect port for each service. It means we must manually hard-code each unique inspector port for each micro-service config.

@cjihrig
Copy link
Contributor

cjihrig commented Jun 27, 2019

If you pass 0 as the port number, you'll get a random, available port.

@gustavomassa
Copy link
Author

gustavomassa commented Jun 27, 2019

@cjihrig Thank you! I did not know about passing 0, the inspector documentation needs to be updated.
https://nodejs.org/en/docs/inspector
https://nodejs.org/en/docs/guides/debugging-getting-started/

command: ["node", "--max_old_space_size=512", "--nolazy", "--no-warnings", "--expose-gc", "--inspect=0.0.0.0:0", "dist/src/Main.js"]
image

@vhuty
Copy link

vhuty commented Jul 8, 2024

The "zero-port behavior" is not documented at the moment. Is it still valid?

@RedYetiDev
Copy link
Member

That behavior is still valid, I've opened a PR to document it: #53782

@steelbrain
Copy link

Apologies for the miscommunication. I wrote earlier that it didn't work (and then deleted the comment because I found out soon after that I was wrong).

The error I was running into was produced by a userland thing, not node itself

@juanbomfim22
Copy link

If you pass 0 as the port number, you'll get a random, available port.

That's fantastic.

Important

The port should be a number, beware of passing a string as '0'.

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

No branches or pull requests

6 participants