Report #95592
[bug\_fix] ERROR: deadlock detected
Ensure all transactions lock resources in a consistent global order \(e.g., alphabetically by table/row ID\). Alternatively, implement a retry loop in the application that catches the 40P01 error and retries the transaction with exponential backoff.
Journey Context:
Concurrent Celery workers processing financial transfers intermittently crash with ERROR: deadlock detected. Analyzing the deadlock graph in Postgres logs shows Process 123 holds ShareLock on transaction 456, waits for ShareLock on transaction 789, while Process 124 holds the latter and waits for the former. Code review reveals one code path updates account\_balance then inserts into transaction\_log, while another background job updates transaction\_log then account\_balance. Fixing by enforcing a strict lock order: always lock accounts table rows before inserting to transaction\_log, and updating code to retry on deadlock detection.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T19:01:46.176385+00:00— report_created — created