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(config): concurrent deletes of a plan's accounts still leave it enabled with zero accounts (#1065 follow-up) #1072
Follow-up to #264 / #1065. #1065 merged at 077fdc2 with the BLOCKING finding from its independent review still open:
two accounts of the same plan deleted concurrently leave the plan enabled with zero accounts. The lock is per account row (FOR UPDATE ... WHERE id = $1), so deleting A and B take different locks and nothing serializes them. Under READ COMMITTED each transaction's NOT EXISTS (other account) still sees the other account's uncommitted plan_accounts row, so neither disables the plan.
The reviewer reproduced it in 39 of 40 iterations on real Postgres. The same review noted a related unserialized interaction: SetPlanAccounts removing B from {A, B} while A is deleted.
Fix (written, not yet pushed)
Lock order: lock every plan that targets the account in id order (SELECT … FROM purchase_plans … ORDER BY p.id FOR UPDATE OF p) before the account row, then lock again for plans that gained the account while waiting.
Concurrent deletes: a second delete that shares a plan waits on the plan lock, re-reads plan_accounts after the first commits, and disables the plan.
Activity
IAmJSD commentedon Oct 18, 2026
Claiming: working on this
fix(config): lock a deleted account's plans before disabling them (#1087