Skip to content

hub: resolve and announce the actual bound port for a configured 0#90

Open
andig wants to merge 1 commit into
enbility:devfrom
andig:feat/hub-bound-port
Open

hub: resolve and announce the actual bound port for a configured 0#90
andig wants to merge 1 commit into
enbility:devfrom
andig:feat/hub-bound-port

Conversation

@andig

@andig andig commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

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'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.SetPort updates the announced port when the configured port was 0; fixed-port callers are unaffected (the call is gated on h.port == 0, so no existing mock expectations needed touching beyond the port-0 test paths).

Test

TestHub_BoundPort_ResolvesRealPortForEphemeralConfig asserts Port() resolves a real port and that SetPort is called with that exact value.

Verified both falsification angles:

  • Without Port()/SetPort at all: compile error (not by itself meaningful).
  • With Port() present but the SetPort call 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-based hub package tests that construct a hub with port 0 (updated with SetPort expectations where they exercise a real Start()).

🤖 Generated with Claude Code

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.
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 92.891% (-0.08%) from 92.972% — andig:feat/hub-bound-port into enbility:dev

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.

2 participants