fix(process): capture health server in serve goroutine

This commit is contained in:
Virgil 2026-04-03 23:10:33 +00:00
parent f94b83fe6d
commit e2f84b69e1
2 changed files with 11 additions and 4 deletions

View file

@ -92,12 +92,13 @@ func (h *HealthServer) Start() error {
return core.E("health.start", core.Concat("failed to listen on ", h.addr), err)
}
server := &http.Server{Handler: mux}
h.listener = listener
h.server = &http.Server{Handler: mux}
h.server = server
go func() {
_ = h.server.Serve(listener)
}()
go func(srv *http.Server, ln net.Listener) {
_ = srv.Serve(ln)
}(server, listener)
return nil
}

View file

@ -66,6 +66,12 @@ func TestHealthServer_WithChecks_Good(t *testing.T) {
_ = resp.Body.Close()
}
func TestHealthServer_StopImmediately_Good(t *testing.T) {
hs := NewHealthServer("127.0.0.1:0")
require.NoError(t, hs.Start())
require.NoError(t, hs.Stop(context.Background()))
}
func TestWaitForHealth_Reachable_Good(t *testing.T) {
hs := NewHealthServer("127.0.0.1:0")
require.NoError(t, hs.Start())