You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(server): StartHTTPServer shutdown does not wait for background DB init #664
Found by the independent re-review of #646 at 574caf4.
StartHTTPServer (internal/server/http.go:162-186) starts the background initializer with app.startBackgroundInit(sigCtx) (http.go:113) but never waits for it. On SIGTERM it runs server.Shutdown, returns nil, and cmd/server/main.go:52 runs defer app.Close() while ensureDB may still be running.
Effects (not fatal; Close still runs):
app.Close() (internal/server/app.go:949) reads app.DB without a lock while ensureDB may be writing it. That is a data race, and a pool created just after Close read nil is never closed.
runMigrationsBounded takes a pool, not a context, so SIGTERM mid-migration is not interrupted; the process exit kills it mid-run.
Fix sketch: make startBackgroundInit return a channel closed when initializeUntilReady exits, and have StartHTTPServer wait on it after server.Shutdown, inside the same 30s shutdownCtx. A draft with a test (TestRunUntilReadyClosesDoneAfterInitializerExits) passes locally: ~/.claude/agent-comms/messages/draft-20261008-646-f4-shutdown-wait.patch.
Deferred out of #646 by the fleet lead; to be done as a follow-up PR after #646 merges.
Activity
fix(server): wait for background DB init before returning from shutdown