File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
lib/active_record/connection_adapters/abstract Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -668,7 +668,13 @@ def acquire_connection(checkout_timeout)
668
668
conn
669
669
else
670
670
reap
671
- @available . poll ( checkout_timeout )
671
+ # Retry after reaping, which may return an available connection,
672
+ # remove an inactive connection, or both
673
+ if conn = @available . poll || try_to_checkout_new_connection
674
+ conn
675
+ else
676
+ @available . poll ( checkout_timeout )
677
+ end
672
678
end
673
679
rescue ConnectionTimeoutError => ex
674
680
raise ex . set_pool ( self )
Original file line number Diff line number Diff line change @@ -216,6 +216,30 @@ def test_reap_inactive
216
216
@pool . connections . each { |conn | conn . close if conn . in_use? }
217
217
end
218
218
219
+ def test_inactive_are_returned_from_dead_thread
220
+ ready = Concurrent ::CountDownLatch . new
221
+ @pool . instance_variable_set ( :@size , 1 )
222
+
223
+ child = new_thread do
224
+ @pool . checkout
225
+ ready . count_down
226
+ stop_thread
227
+ end
228
+
229
+ pass_to ( child ) until ready . wait ( 0 )
230
+
231
+ assert_equal 1 , active_connections ( @pool ) . size
232
+
233
+ child . terminate
234
+ child . join
235
+
236
+ @pool . checkout
237
+
238
+ assert_equal 1 , active_connections ( @pool ) . size
239
+ ensure
240
+ @pool . connections . each { |conn | conn . close if conn . in_use? }
241
+ end
242
+
219
243
def test_idle_timeout_configuration
220
244
@pool . disconnect!
221
245
You can’t perform that action at this time.
0 commit comments