Module: ActiveRecordDeadlockHandler::ConnectionAdapterPatch
- Defined in:
- lib/active_record_deadlock_handler/connection_adapter_patch.rb
Overview
Prepended into ActiveRecord::ConnectionAdapters::DatabaseStatements to wrap every top-level transaction with deadlock retry logic.
Instance Method Summary collapse
-
#transaction(**options, &block) ⇒ Object
Wraps transaction with retry logic only at the outermost transaction level.
Instance Method Details
#transaction(**options, &block) ⇒ Object
Wraps transaction with retry logic only at the outermost transaction level.
Nested transactions (savepoints) are NOT wrapped individually — when a deadlock kills a transaction, the entire outer transaction is invalidated. Retrying only a savepoint inside a dead transaction would corrupt state. The outer retry loop handles the full re-execution.
13 14 15 16 17 18 19 20 21 |
# File 'lib/active_record_deadlock_handler/connection_adapter_patch.rb', line 13 def transaction(**, &block) # open_transactions > 0 means we're already inside a real transaction. # Let it pass through; the outermost call's retry loop covers everything. return super(**, &block) if open_transactions > 0 RetryExecutor.run(config: ActiveRecordDeadlockHandler.configuration) do super(**, &block) end end |