Skip to content

store: apply a new database's migrations in one transaction - #61

Merged
Omar-VF merged 1 commit into
Liquid-co:dev-publicfrom
ChakraFusion:pr/daemon-start-fix
Oct 15, 2026
Merged

Omar-VF merged 1 commit into
Liquid-co:dev-publicfrom
ChakraFusion:pr/daemon-start-fix

Conversation

@ChakraFusion

Copy link
Copy Markdown

The cause of "daemon never became ready" on Windows CI (seen on #51, CI #319: TestFreshRestore_SnapshotModeReportsWhatItImported).

Cause: a new database applied each of its 37 migrations in a transaction of its own. Every commit flushes the journal and the database to disk, which made 156 fsyncs before store.Open returned. On a busy Windows runner that took over 30 s, past the CLI harness's readiness wait.

  • In a long hunt on Windows runners, startup markers put 94% of slow-start time in store.Open (median 8.0 s, max 18.8 s).
  • A stack dump of a daemon that missed the deadline was still in store.Open → migrate → FlushFileBuffers.
  • The failure reproduced 10 times in about 28,000 runs of the daemon-starting tests.

Fix: all pending migrations go in one transaction: 8 fsyncs for a new database, none for one that's up to date. A failed step now leaves the schema as it was instead of half-upgraded.

Tests (internal/store/migrate_test.go, using the driver's commit hook):

  • TestOpeningANewDatabaseCommitsOnce: 38 commits before the change, 1 after;
  • TestOpeningAnUpToDateDatabaseDoesNotCommit;
  • TestAFailedMigrationAppliesNothing.

After the fix: 0 "never ready" in about 52,000 runs (store.Open median 3.6 s, max 7.7 s).

Notes:

🤖 Generated with Claude Code

A new database applied each of its 37 migrations in a transaction of its
own, and every commit flushes the rollback journal and the database to disk:
156 fsyncs before store.Open returned. On a busy Windows CI runner that took
over thirty seconds, so a freshly started daemon could miss the 30s the CLI
e2e harness gives it. CI failed with "daemon never became ready" and empty
output; a goroutine dump of the daemon at the deadline shows it still in
store.Open -> migrate -> tx.Commit -> FlushFileBuffers, and its log says it
started 1.5s after the test gave up. Starts of 5 to 20 seconds, all spent
before the address was published, were common on the same runners.

Pending migrations now go in one transaction: one commit, 8 fsyncs for a
new database (counted with strace), none for one already up to date. A
failed step now leaves the schema as it was instead of half upgraded.

TestOpeningANewDatabaseCommitsOnce counts commits with the driver's commit
hook: 38 before this change, 1 after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vercel

vercel Bot commented Oct 15, 2026

Copy link
Copy Markdown

@claude is attempting to deploy a commit to the sivadaboi's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

3 participants