Skip to content

fix(storage): bound AutoMigrate with configurable deadline#65

Merged
aksOps merged 1 commit into
mainfrom
fix/automigrate-timeout
Apr 28, 2026
Merged

fix(storage): bound AutoMigrate with configurable deadline#65
aksOps merged 1 commit into
mainfrom
fix/automigrate-timeout

Conversation

@aksOps

@aksOps aksOps commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Summary

PR C of 6. Closes the startup-hang gap: `db.AutoMigrate` had no deadline, so a Postgres relation-lock wait blocked startup indefinitely with no log output.

  • New env var `DB_MIGRATE_TIMEOUT_SECS` (default 60s, max 1h, set 0 to opt out)
  • Threaded through `MigrateOptions.Timeout` into a context applied to the AutoMigrate call only via `db.WithContext`
  • Pre/post hooks (FTS5 triggers, legacy index drops) intentionally remain unbounded — they don't acquire long-held locks

Test plan

  • `go test -race -count=1 ./internal/storage/...` → 182 passed (was 175, +7 new)
  • migrateTimeoutFromEnv covers default, explicit value, opt-out, malformed, cap, whitespace
  • AutoMigrateModelsWithOptions exercised with both Timeout=30s and Timeout=0 paths

🤖 Generated with Claude Code

Without a timeout, db.AutoMigrate inherits no deadline. On Postgres
under load, an ALTER TABLE waits indefinitely for a relation lock —
hanging the entire binary startup with no log output and requiring
kill -9 to recover.

Adds DB_MIGRATE_TIMEOUT_SECS (default 60s, max 1h, set 0 to opt out)
and threads it through MigrateOptions.Timeout into a context applied
to the AutoMigrate call only via db.WithContext. Pre/post hooks
(FTS5 setup, legacy index drops) remain unbounded since they don't
take long-held locks.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@aksOps aksOps merged commit d42c19c into main Apr 28, 2026
17 checks passed
@aksOps aksOps deleted the fix/automigrate-timeout branch April 28, 2026 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant