Artifact b7f7fb2a407528afb0d83451d23fee30a89e55ac88a0546758082ab7d4288c87:
- File
hub/assert.go
— part of check-in
[8a18ec9ebe]
at
2026-05-19 18:54:41
on branch fix/hub-stop-servehttp-race-tigerstyle
— fix(hub): single-owner httpServer construction in NewHub (closes 187)
TigerStyle: eliminate the shared mutable state instead of guarding it.
Move mux + http.Server construction from ServeHTTP into NewHub. After NewHub returns, h.httpServer and h.httpListener are immutable for the hubs lifetime — single writer (NewHub), many readers (ServeHTTP, Stop). No mutex, no atomic, no sync.Once required: the race is gone by construction.
Add a hub package-private assert helper and positive invariants at entry to ServeHTTP and Stop, surfacing programmer-bugs loudly instead of silently UB-ing on a nil httpServer.
Fixes the 3 data races in TestCrossSessionAutosync and the 3 in TestScope_Project_ConcurrentCommits under -race; hub package suite green at -race -count=3. (user: 41898282+github-actions[bot]@users.noreply.github.com, size: 581) [annotate] [blame] [check-ins using] [more...]
package hub import "fmt" // assert panics with msg when cond is false. TigerStyle-flavored runtime // invariant check: programmer-bugs (e.g. an internal lifecycle invariant // violated) surface loudly instead of as silent undefined behavior or a // remote nil-pointer panic deeper in the stack. // // Use sparingly and only for invariants the package itself controls — never // for input validation, which belongs on the public API surface as a typed // error return. func assert(cond bool, msg string) { if !cond { panic(fmt.Sprintf("hub: assertion failed: %s", msg)) } }