File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed
activerecord/lib/active_record/connection_adapters/abstract Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -545,20 +545,25 @@ def clear_reloadable_connections!
545
545
# Raises:
546
546
# - ActiveRecord::ConnectionTimeoutError no connection can be obtained from the pool.
547
547
def checkout ( checkout_timeout = @checkout_timeout )
548
- if @pinned_connection
549
- @pinned_connection . lock . synchronize do
550
- synchronize do
548
+ return checkout_and_verify ( acquire_connection ( checkout_timeout ) ) unless @pinned_connection
549
+
550
+ @pinned_connection . lock . synchronize do
551
+ synchronize do
552
+ # The pinned connection may have been cleaned up before we synchronized, so check if it is still present
553
+ if @pinned_connection
551
554
@pinned_connection . verify!
555
+
552
556
# Any leased connection must be in @connections otherwise
553
557
# some methods like #connected? won't behave correctly
554
558
unless @connections . include? ( @pinned_connection )
555
559
@connections << @pinned_connection
556
560
end
561
+
562
+ @pinned_connection
563
+ else
564
+ checkout_and_verify ( acquire_connection ( checkout_timeout ) )
557
565
end
558
566
end
559
- @pinned_connection
560
- else
561
- checkout_and_verify ( acquire_connection ( checkout_timeout ) )
562
567
end
563
568
end
564
569
You can’t perform that action at this time.
0 commit comments