Skip to content

Commit

Permalink
Use lock syncronize on transaction rollback (#73)
Browse files Browse the repository at this point in the history
Avoids race conditions between counting the number of open transactions
and calling rollback.

Co-authored-by: Malcolm Locke <[email protected]>
  • Loading branch information
malclocke and Malcolm Locke authored Jul 12, 2024
1 parent c8bd3cd commit e8835a1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/database_cleaner/active_record/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ def start

def clean
connection_class.connection_pool.connections.each do |connection|
next unless connection.open_transactions > 0
connection.rollback_transaction
connection.lock.synchronize do
next unless connection.open_transactions > 0
connection.rollback_transaction
end
end
end
end
Expand Down

0 comments on commit e8835a1

Please sign in to comment.