mirror of https://github.com/rails/rails
Merge pull request #50190 from jhawthorn/retry_checkout_after_reap
Retry new connection on checkout after reap
This commit is contained in:
commit
c80fa6a069
|
@ -668,7 +668,13 @@ module ActiveRecord
|
|||
conn
|
||||
else
|
||||
reap
|
||||
@available.poll(checkout_timeout)
|
||||
# Retry after reaping, which may return an available connection,
|
||||
# remove an inactive connection, or both
|
||||
if conn = @available.poll || try_to_checkout_new_connection
|
||||
conn
|
||||
else
|
||||
@available.poll(checkout_timeout)
|
||||
end
|
||||
end
|
||||
rescue ConnectionTimeoutError => ex
|
||||
raise ex.set_pool(self)
|
||||
|
|
|
@ -216,6 +216,30 @@ module ActiveRecord
|
|||
@pool.connections.each { |conn| conn.close if conn.in_use? }
|
||||
end
|
||||
|
||||
def test_inactive_are_returned_from_dead_thread
|
||||
ready = Concurrent::CountDownLatch.new
|
||||
@pool.instance_variable_set(:@size, 1)
|
||||
|
||||
child = new_thread do
|
||||
@pool.checkout
|
||||
ready.count_down
|
||||
stop_thread
|
||||
end
|
||||
|
||||
pass_to(child) until ready.wait(0)
|
||||
|
||||
assert_equal 1, active_connections(@pool).size
|
||||
|
||||
child.terminate
|
||||
child.join
|
||||
|
||||
@pool.checkout
|
||||
|
||||
assert_equal 1, active_connections(@pool).size
|
||||
ensure
|
||||
@pool.connections.each { |conn| conn.close if conn.in_use? }
|
||||
end
|
||||
|
||||
def test_idle_timeout_configuration
|
||||
@pool.disconnect!
|
||||
|
||||
|
|
Loading…
Reference in New Issue