Skip to content

Commit e8835a1

Browse files
malclockeMalcolm Locke
andauthored
Use lock syncronize on transaction rollback (#73)
Avoids race conditions between counting the number of open transactions and calling rollback. Co-authored-by: Malcolm Locke <malc@riparide.com>
1 parent c8bd3cd commit e8835a1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/database_cleaner/active_record/transaction.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ def start
1919

2020
def clean
2121
connection_class.connection_pool.connections.each do |connection|
22-
next unless connection.open_transactions > 0
23-
connection.rollback_transaction
22+
connection.lock.synchronize do
23+
next unless connection.open_transactions > 0
24+
connection.rollback_transaction
25+
end
2426
end
2527
end
2628
end

0 commit comments

Comments
 (0)