Expand description
Database contention detection utility.
Detects transient lock-contention errors that are safe to retry.
The entire transaction must be retried from BEGIN — not just the
failing statement — because the database has already rolled it back.
§Covered engines
-
MySQL/MariaDB—InnoDBdeadlock (SQLSTATE40001).InnoDBdetects deadlocks instantly and rolls back one transaction.“Always be prepared to re-issue a transaction if it fails due to deadlock. Deadlocks are not dangerous. Just try again.” — MySQL 8.0 Reference Manual, InnoDB Deadlocks
-
PostgreSQL— serialization failure (SQLSTATE40001) and deadlock detected (SQLSTATE40P01).“Applications using this level must be prepared to retry transactions due to serialization failures.” — PostgreSQL docs, Transaction Isolation
-
SQLite—SQLITE_BUSY(code 5) andSQLITE_BUSY_SNAPSHOT(code 517).SQLitesupports only one writer at a time; concurrent writers receiveSQLITE_BUSYwhen thebusy_timeoutexpires, orSQLITE_BUSY_SNAPSHOTimmediately when a WAL snapshot cannot be upgraded. See Result Codes — SQLITE_BUSY.
§Backend dispatch
The caller must supply the DbBackend so that pattern matching is scoped
to the correct engine, avoiding false positives from shared SQLSTATE codes
(e.g., 40001 means different things in MySQL vs PostgreSQL).
This module provides detection helpers for callers that manage their own transaction lifecycle (e.g., the outbox sequencer).
Functions§
- is_
retryable_ contention - Returns
trueif the error is a transient lock-contention error that is safe to retry.