Skip to content

Use next available port when the default port is already used #2682

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 3 commits into
base: main
Choose a base branch
from

Conversation

PramodValavala-MSFT
Copy link
Contributor

When working with multiple function apps locally, every function host apart from the first needs to have a different port manually set either via the command line argument --port or the Host.LocalHttpPort property in local.settings.json. Also, in some cases the default port might be blocked with another process (sometimes an older func itself that didn't terminate).

This PR adds support to pick up the next available port (7072, 7073, ...) when none is provided. If a port is defined in either place mentioned above, this would not do anything.

One known issue is that multiple function apps run at the exact same time might end up picking the same port, causing one of them to error out. This is present even today with the static default port, primarily because the validation is done before the host starts up.

@liliankasem
Copy link
Member

@kshyju I noticed you flagged this for discussion, have you looked into this further?

}
startPort++;
}

Choose a reason for hiding this comment

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

What if all ports are exhausted, then should we log the errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After checking the ports after the start port, the GetAvailablePort method will try to get any available port at random.

@liliankasem
Copy link
Member

@PramodValavala-MSFT thank you for the contribution, can you please address the PR feedback?

@liliankasem liliankasem changed the base branch from v3.x to main March 13, 2025 20:18
@liliankasem liliankasem requested a review from a team as a code owner March 13, 2025 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants