feat: report the port a server is listening on - #6
Merged
Merged
Conversation
`TcpTransport` took a port and told nobody what it did with it, so `port=0` bound an ephemeral port that nothing could discover. `Server.port` now reports it. To make the assigned port knowable, the listener binds in `start()` rather than in the accept task it spawns — the bound address doesn't exist until something calls `local_addr`, and nothing could, from inside a task that had already been handed off.
sash-a
force-pushed
the
feat/server-port-getter
branch
from
August 29, 2026 09:25
9391489 to
842deb1
Compare
sash-a
commented
Aug 29, 2026
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.
Problem
TcpTransporttakes a port and tells nobody what it did with it — the field is private on a frozen pyclass, and_Servernever exposes its transport. SoTcpTransport(port=0)bound an ephemeral port that nothing could discover.Change
Server.portraisesRuntimeErrorbeforestart()and without a transport.Transport::porton the Rust trait defaults toNonefor transports that don't listen on a TCP port.The one non-obvious part: the listener now binds in
start()instead of in the accept task it spawns. The bound address doesn't exist until something callslocal_addr, and nothing could from inside a task that had already been handed to the runtime. Moving the bind is what makes the port knowable at all.One behaviour change falls out of that: a failed bind (port in use) now raises from
start(). It previously only reached stderr, withstart()returning successfully on a server that was never listening.