⚡ Add an expiring, renewed lease to the account mutation lock #18
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/account-mutation-lock-lease"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hit three times live on Fanyu in one session: the account-mutation lock (guards account/project-member/supplier writes) had no expiring lease by design, so a worker pod replacement mid-hold (a routine rolling deploy) left the lock permanently stuck, requiring a manual mongosh intervention each time.
Adds a renewed lease (ACCOUNT_MUTATION_LOCK_LEASE_SECONDS, default 2m), mirroring the project-deletion task lease's own renewal ticker already in this codebase. A live owner renews every leaseDuration/4 so its lease never lapses; only a lock whose owner stopped renewing (crashed/replaced) becomes reclaimable, once lapsed. Reclaiming assigns a fresh owner id, which already acts as a fencing token — the original holder's release (matched on owner) can never succeed afterward or touch the new holder's lock. Transient renewal errors don't give up early; only a confirmed loss does.
Tests: go build/vet clean, go test ./internal/api/... ./internal/store/... ./internal/worker/... — identical failure set to unmodified dev (verified via stash diff, baseline is 76, unrelated to this change), race detector clean on internal/store. Added TestAccountMutationLockLeaseReclaimAndRenewal (live-Mongo gated) covering normal round-trip, lapsed-lease reclaim, and renewed-lease blocking a concurrent reclaim.
🤖 Generated with Claude Code