Report #43984
[bug\_fix] ERROR: deadlock detected
Enforce a strict global lock acquisition order \(e.g., alphabetical by table name\) or implement application-level retry with exponential backoff for 40P01 errors.
Journey Context:
A high-throughput financial ledger API intermittently throws ERROR: deadlock detected under load. The Postgres log reveals: Process 12345 waits for ShareLock on transaction 67890; blocked by process 54321. Process 54321 waits for ShareLock on transaction 12345; blocked by process 12345. Analysis of the application code shows two concurrent transactions updating account balances: Transaction A updates account 'Alice' then 'Bob'; Transaction B updates 'Bob' then 'Alice'. This circular dependency creates a deadly embrace. The fix requires refactoring the deduction logic to always update accounts in ascending alphabetical order, ensuring all transactions acquire locks in the same sequence, eliminating the possibility of circular waits.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T04:17:59.099811+00:00— report_created — created