Skip to content

Fix: Log actual API port when configured with port 0#1576

Merged
garrytrinder merged 1 commit intomainfrom
copilot/fix-api-port-logging
Mar 2, 2026
Merged

Fix: Log actual API port when configured with port 0#1576
garrytrinder merged 1 commit intomainfrom
copilot/fix-api-port-logging

Conversation

Copy link
Contributor

Copilot AI commented Mar 1, 2026

When starting Dev Proxy with --api-port 0, the log message emitted port 0 instead 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 an ApplicationStarted callback, so it fires after Kestrel has fully bound. Uses IServerAddressesFeature to read the actual bound address, with a fallback to configured values.
// Before
Dev Proxy API listening on http://127.0.0.1:0...

// After
Dev Proxy API listening on http://127.0.0.1:49977...
Original prompt

This section details on the original issue you should resolve

<issue_title>Fix: Log actual API port when configured with port 0</issue_title>
<issue_description>## Bug
When starting Dev Proxy with --api-port 0, the log message shows the unresolved port 0 instead of the actual assigned port.

Steps to reproduce

devproxy --as-system-proxy false --port 0 --api-port 0

Current behavior

Dev Proxy API listening on http://127.0.0.1:0...
Dev Proxy listening on 127.0.0.1:49978...

Expected behavior

Dev Proxy API listening on http://127.0.0.1:49977...
Dev Proxy listening on 127.0.0.1:49978...

The proxy port is logged correctly after resolution, but the API port shows 0.

Location

The log message is in DevProxy/Commands/DevProxyCommand.cs around line 263.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

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
@waldekmastykarz waldekmastykarz marked this pull request as ready for review March 1, 2026 10:07
@waldekmastykarz waldekmastykarz requested a review from a team as a code owner March 1, 2026 10:07
Copilot AI review requested due to automatic review settings March 1, 2026 10:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 ApplicationStarted callback.
  • Reads the bound address from IServerAddressesFeature (with a fallback to configured IP/port) and logs it.

Copy link
Contributor

@garrytrinder garrytrinder left a comment

Choose a reason for hiding this comment

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

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.

@garrytrinder garrytrinder enabled auto-merge (squash) March 2, 2026 10:23
Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
@garrytrinder garrytrinder force-pushed the copilot/fix-api-port-logging branch from b02386d to 90203fb Compare March 2, 2026 11:07
@garrytrinder garrytrinder merged commit e332ec7 into main Mar 2, 2026
4 checks passed
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

Successfully merging this pull request may close these issues.

Fix: Log actual API port when configured with port 0

4 participants