From 9ac181dbf47882b522fe56718ba3fea957ded431 Mon Sep 17 00:00:00 2001 From: Quick <31828688+Quick104@users.noreply.github.com> Date: Thu, 28 May 2026 20:39:08 -0400 Subject: [PATCH] fix(startup): recover from panics in deferred background init The deferred background-init steps run in a detached goroutine after the HTTP listener is already accepting connections. An unrecovered panic in any step (queue seeding, legacy cleanup, scrobble sweep) would crash the entire live server. Wrap each step in a recover that logs the panic with a stack and continues to the next step. Found during PR #21 review. Co-Authored-By: Claude Opus 4.8 (1M context) --- cmd/silo/main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/silo/main.go b/cmd/silo/main.go index 819ecd96..1305fed6 100644 --- a/cmd/silo/main.go +++ b/cmd/silo/main.go @@ -15,6 +15,7 @@ import ( "os" "os/signal" "path/filepath" + "runtime/debug" "strconv" "strings" "syscall" @@ -1677,7 +1678,15 @@ func main() { if appCtx.Err() != nil { return } - step(appCtx) + func() { + defer func() { + if p := recover(); p != nil { + slog.Error("deferred startup init step panicked; continuing", + "panic", p, "stack", string(debug.Stack())) + } + }() + step(appCtx) + }() } slog.Info("deferred startup init completed", "steps", len(backgroundInit), "duration", time.Since(start)) }()