hub: resolve and announce the actual bound port for a configured 0#90
Open
andig wants to merge 1 commit into
Open
hub: resolve and announce the actual bound port for a configured 0#90andig wants to merge 1 commit into
andig wants to merge 1 commit into
Conversation
startWebsocketServer bound the websocket listener implicitly inside ListenAndServeTLS, so a configured port of 0 (OS-assigned) was never resolvable - Hub had no way to report the real port, and mDNS kept announcing the literal configured value, which mdns.go already rejects as invalid (<= 0). Listen synchronously instead, so a bind failure surfaces immediately and the real bound port is known before mDNS starts. Add Hub.Port() to expose it, and MdnsInterface.SetPort to update the announced port when the configured port was 0; fixed-port callers are unaffected. TestHub_BoundPort_ResolvesRealPortForEphemeralConfig proves both: it fails to compile without Port(), and fails on a live assertion (mDNS told port 0 instead of the real one) if the SetPort call is removed.
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.
startWebsocketServerbound the websocket listener implicitly insideListenAndServeTLS, so a configured port of 0 (OS-assigned) was never resolvable -Hubhad no way to report the real port, and mDNS kept announcing the literal configured value, whichmdns.go's own validation already rejects as invalid (port <= 0).Listen synchronously instead, so a bind failure surfaces immediately (as a bonus, this also removes the pre-existing 100ms poll-and-hope window in
Start()for detecting bind failures) and the real bound port is known before mDNS starts.Hub.Port()exposes the actual bound port.MdnsInterface.SetPortupdates the announced port when the configured port was 0; fixed-port callers are unaffected (the call is gated onh.port == 0, so no existing mock expectations needed touching beyond the port-0 test paths).Test
TestHub_BoundPort_ResolvesRealPortForEphemeralConfigassertsPort()resolves a real port and thatSetPortis called with that exact value.Verified both falsification angles:
Port()/SetPortat all: compile error (not by itself meaningful).Port()present but theSetPortcall removed: the test still compiles and runs, and fails on a live assertion (expected: <real port>, actual: 0- "mDNS must be told the actual bound port, not the configured 0").Full suite green (
go build/vet/test ./...), including the pre-existing gomock-basedhubpackage tests that construct a hub with port 0 (updated withSetPortexpectations where they exercise a realStart()).🤖 Generated with Claude Code