Skip to content

Commit

Permalink
Check if pinned connection is still available before checking it out
Browse files Browse the repository at this point in the history
  • Loading branch information
SjoerdL committed Dec 27, 2024
1 parent c31cc0b commit b7a5dc4
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,20 +545,25 @@ def clear_reloadable_connections!
# Raises:
# - ActiveRecord::ConnectionTimeoutError no connection can be obtained from the pool.
def checkout(checkout_timeout = @checkout_timeout)
if @pinned_connection
@pinned_connection.lock.synchronize do
synchronize do
return checkout_and_verify(acquire_connection(checkout_timeout)) unless @pinned_connection

@pinned_connection.lock.synchronize do
synchronize do
# The pinned connection may have been cleaned up before we synchronized, so check if it is still present
if @pinned_connection
@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

@pinned_connection
else
checkout_and_verify(acquire_connection(checkout_timeout))
end
end
@pinned_connection
else
checkout_and_verify(acquire_connection(checkout_timeout))
end
end

Expand Down

0 comments on commit b7a5dc4

Please sign in to comment.