Skip to content

Commit

Permalink
Merge pull request rails#52235 from fatkodima/fix-deadlock-in-checkout
Browse files Browse the repository at this point in the history
Fix a deadlock in `ConnectionPool#checkout`
  • Loading branch information
byroot authored Jun 29, 2024
2 parents 21280a1 + 803c78d commit d2b739c
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -541,12 +541,14 @@ def clear_reloadable_connections!
# - ActiveRecord::ConnectionTimeoutError no connection can be obtained from the pool.
def checkout(checkout_timeout = @checkout_timeout)
if @pinned_connection
synchronize do
@pinned_connection.verify!
# Any leased connection must be in @connections otherwise
# some methods like #connected? won't behave correctly
unless @connections.include?(@pinned_connection)
@connections << @pinned_connection
@pinned_connection.lock.synchronize do
synchronize do
@pinned_connection.verify!
# Any leased connection must be in @connections otherwise
# some methods like #connected? won't behave correctly
unless @connections.include?(@pinned_connection)
@connections << @pinned_connection
end
end
end
@pinned_connection
Expand Down

0 comments on commit d2b739c

Please sign in to comment.