提交 656961c7 编写于 作者: J John Hawthorn

Merge pull request #36999 from rails/reaper_fork2

Fix error on reap/flush for closed connection pool
上级 4d3f0217
......@@ -650,6 +650,7 @@ def remove(conn)
# or a thread dies unexpectedly.
def reap
stale_connections = synchronize do
return unless @connections
@connections.select do |conn|
conn.in_use? && !conn.owner.alive?
end.each do |conn|
......@@ -674,6 +675,7 @@ def flush(minimum_idle = @idle_timeout)
return if minimum_idle.nil?
idle_connections = synchronize do
return unless @connections
@connections.select do |conn|
!conn.in_use? && conn.seconds_idle >= minimum_idle
end.each do |conn|
......
......@@ -82,6 +82,37 @@ def test_connection_pool_starts_reaper
assert_not_predicate conn, :in_use?
end
def test_reaper_works_after_pool_discard
spec = ActiveRecord::Base.connection_pool.spec.dup
spec.config[:reaping_frequency] = "0.0001"
2.times do
pool = ConnectionPool.new spec
conn, child = new_conn_in_thread(pool)
assert_predicate conn, :in_use?
child.terminate
wait_for_conn_idle(conn)
assert_not_predicate conn, :in_use?
pool.discard!
end
end
# This doesn't test the reaper directly, but we want to test the action
# it would take on a discarded pool
def test_reap_flush_on_discarded_pool
spec = ActiveRecord::Base.connection_pool.spec.dup
pool = ConnectionPool.new spec
pool.discard!
pool.reap
pool.flush
end
def test_connection_pool_starts_reaper_in_fork
spec = ActiveRecord::Base.connection_pool.spec.dup
spec.config[:reaping_frequency] = "0.0001"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册