fix(T-1031): Graceful server shutdown returns http.ErrServerClosed#156
Conversation
Code ReviewOverviewThis PR fixes a cosmetic-but-meaningful bug where The Fix Is Correct
It signals intentional server shutdown, not an actual failure. Both if err != nil && err != http.ErrServerClosed {
return fmt.Errorf("server error: %w", err)
}But then the old code leaked Caller Analysis
errCh := make(chan error, 1)
go func() { errCh <- server.Start() }()
select {
case sig := <-sigCh:
return server.Shutdown(ctx) // Already returned; errCh is drained by buffer
case err := <-errCh:
return err // Now gets nil instead of ErrServerClosed ✓
}
errChan := make(chan error, 1)
go func() { errChan <- server.Start() }()
select {
case sig := <-sigChan:
return server.Shutdown(ctx) // Already returned; errChan is drained by buffer
case err := <-errChan:
return err // Now gets nil instead of ErrServerClosed ✓
}Both callers would have previously propagated Suggestions1. Tighten existing tests to assert Both server test files currently accept // internal/apsisweb/server_test.go and internal/web/server_test.go
if err != nil && err != http.ErrServerClosed {
t.Errorf("unexpected server error: %v", err)
}This condition passes for both if err != nil {
t.Errorf("Start() after graceful shutdown should return nil, got: %v", err)
}Not a blocker, but it would make the tests enforce the intended contract. 2. Pre-existing: double signal handling in
Summary
LGTM with the optional test tightening as a follow-up. |
9549e9c to
896bc29
Compare
Code Review — PR #156: Graceful server shutdown returns http.ErrServerClosed
OverviewFixes a subtle but real bug in both HTTP server implementations: after a graceful shutdown, CorrectnessThe fix is correct and aligns with the Go standard library's documented recommendation: callers should treat
Code Qualityapsisweb/server.go — clean. The comment already says "Does not handle signals — the caller is responsible for calling Shutdown," which accurately describes the pattern. The fix is consistent with this design. web/server.go — also correct. This server has its own signal handling built into Minor Observations (non-blocking)
SummaryMinimal, targeted, and correct. The fix removes one line of subtle confusion in each file with no added complexity. ✅ |
Fixes Transit ticket T-1031: Graceful server shutdown returns http.ErrServerClosed