Fix: Log actual API port when configured with port 0#1576
Merged
garrytrinder merged 1 commit intomainfrom Mar 2, 2026
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix log message to show actual API port when configured with port 0
Fix: Log actual API port when configured with port 0
Mar 1, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adjusts Dev Proxy’s startup logging so the REST API “listening on …” message reports the actual OS-assigned port when the API is configured with port 0, aligning API logging behavior with how the proxy port is already reported after binding.
Changes:
- Defers the “Dev Proxy API listening on …” log until after Kestrel starts by registering an
ApplicationStartedcallback. - Reads the bound address from
IServerAddressesFeature(with a fallback to configured IP/port) and logs it.
garrytrinder
approved these changes
Mar 2, 2026
Contributor
garrytrinder
left a comment
There was a problem hiding this comment.
Built and tested in detached mode with --api-port 0. Log correctly shows the actual assigned port (e.g., 59279) instead of 0. API confirmed reachable on logged port. Clean fix using ApplicationStarted + IServerAddressesFeature.
Note: the detached mode console output (API URL: http://127.0.0.1:0) still shows port 0 since it reads from state before the server binds — that's a separate issue. LGTM.
Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
b02386d to
90203fb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When starting Dev Proxy with
--api-port 0, the log message emitted port0instead of the OS-assigned port, because the message was logged before Kestrel had started and resolved the ephemeral port.Changes
DevProxy/Commands/DevProxyCommand.cs: Moved the "Dev Proxy API listening on..." log from before_app.RunAsync()into anApplicationStartedcallback, so it fires after Kestrel has fully bound. UsesIServerAddressesFeatureto read the actual bound address, with a fallback to configured values.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.