Concurrent startup can fail while granting database privileges #2082

Closed
opened 2026-11-21 00:46:09 +00:00 by sam · 1 comment
Owner

Problem

Starting two Archie instances against the same fresh PostgreSQL database can make one exit during migration with tuple concurrently updated while granting runtime privileges.

Reproduce

Start both instances concurrently against the same fresh database. One can fail during the runtime privilege grants.

Done when

Concurrent startup serialises or retries the migration and privilege grants safely. Both instances remain running and become ready once the database is available.

## Problem Starting two Archie instances against the same fresh PostgreSQL database can make one exit during migration with `tuple concurrently updated` while granting runtime privileges. ## Reproduce Start both instances concurrently against the same fresh database. One can fail during the runtime privilege grants. ## Done when Concurrent startup serialises or retries the migration and privilege grants safely. Both instances remain running and become ready once the database is available.
sam added the mediumbug labels 2026-11-21 00:46:09 +00:00
Author
Owner

Fixed in 2e48acfc9. pg.Migrate now holds one session-level advisory lock (pg_advisory_lock(hashtextextended('archie.migrate.owner', 0)), on a dedicated connection) across both the goose migrations and the runtime role grants. A second instance waits, then finds the migrations applied and the grants already in place. Goose's own session locker covered only the migrations, so it was removed in favour of the one lock. A migration or grant failure now goes through the existing startup retry with backoff instead of exiting.

Verified: vet, tests and lint, and task check on the merged tree. Not verified: two instances racing against a real fresh database. No test, per the repo rules for races.

Fixed in 2e48acfc9. `pg.Migrate` now holds one session-level advisory lock (`pg_advisory_lock(hashtextextended('archie.migrate.owner', 0))`, on a dedicated connection) across both the goose migrations and the runtime role grants. A second instance waits, then finds the migrations applied and the grants already in place. Goose's own session locker covered only the migrations, so it was removed in favour of the one lock. A migration or grant failure now goes through the existing startup retry with backoff instead of exiting. Verified: vet, tests and lint, and `task check` on the merged tree. Not verified: two instances racing against a real fresh database. No test, per the repo rules for races.
sam closed this issue 2026-11-21 04:02:18 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#2082