-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Choose a random free port #20
Comments
Agreed, it's actually on my TODO list. It's pretty hard to "find a random available port" because there's a big race between the time you find the free port and the time the program binds it. It seems the best way would be to be able to provide a port range to pifpaf that you are sure are available, no matters what. |
I prefer to bind a loopback interface 127.0.0.0/8 (according to the RFC 1700) and always keep the same port. It works on Linux, Windows (loopback adapter) and MacOS On MacOS you must declare the new loopback interface manually like I use this tips to launch multiple versions of PostgreSQL server with loopback that containt the version number in the loopback address and port 5432 like:
|
@kryskool This is a good idea, but it's gonna be tricky if it's not portable out of the box on Darwin :( |
can you not listen on port 0? then ask the program what port it found? |
@jd it might be good to use https://github.com/Yelp/ephemeral-port-reserve/ |
It would be nice to have an option to choose a random free port, and the target program can read it from environment variables.
The text was updated successfully, but these errors were encountered: