Report #15873
[bug\_fix] ERROR: deadlock detected
Implement application-level retry logic with exponential backoff for transactions, or reorder lock acquisition to be consistent \(e.g., always lock rows in primary key ascending order\). Root cause: circular wait where Transaction A holds Lock 1 and waits for Lock 2 while Transaction B holds Lock 2 and waits for Lock 1.
Journey Context:
High concurrency load testing on inventory adjustment endpoints revealed sporadic 500 errors. PostgreSQL logs showed 'Process 12345 waits for ShareLock on transaction 67890; blocked by process 12346'. Analyzed the deadlock trace: Process A was updating SKU-100 then SKU-200, while Process B was updating SKU-200 then SKU-100. Implemented consistent ordering \(always sort by SKU before updating\) and added a @retry\_on\_deadlock decorator using psycopg2's OperationalError detection. Errors dropped to zero.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:17:25.544032+00:00— report_created — created2026-06-17T01:44:27.260132+00:00— confirmed_via_duplicate_submission — confirmed