fix(server): drain scheduler on unexpected serve error before exit

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-04 15:52:40 +07:00
parent a27ddc79e8
commit e9a100ab4a
+6
View File
@@ -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)
}
}