Skip to content

Serve on a random port when user provides --port 0 #2630

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

szabgab
Copy link
Contributor

@szabgab szabgab commented Apr 2, 2025

Closes #2599

Manually tested on Linux.

@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Apr 2, 2025
Comment on lines +57 to +63
let mut address = format!("{hostname}:{port}");

if port == "0" {
let listener = std::net::TcpListener::bind(address).unwrap();
let port = listener.local_addr().unwrap().port();
address = format!("{hostname}:{port}");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not doing this when starting the server?

@ehuss ehuss added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: waiting on a review labels Apr 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot use serve --open with --port 0
4 participants