diff --git a/cmd/server/main.go b/cmd/server/main.go index 08ecbe9..dd40bfd 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -185,6 +185,12 @@ func main() { log.Printf("server stopped") case err := <-serveErr: if err != nil { + // Unwind scheduler.Run via ctx.Done and wait for the in-flight + // RunOnce to finish before exiting, so an unexpected serve error + // mid-run doesn't kill the process during a check/notify write — + // same hazard the ctx.Done branch above already guards against. + stop() + wg.Wait() log.Fatalf("server: %v", err) } }