From b1ac881433b95498e3b63b2686d1e31f1bdb93fc Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 30 Dec 2011 14:31:30 -0800 Subject: connections are only removed if they are inactve --- .../connection_adapters/abstract/connection_pool.rb | 2 +- activerecord/test/cases/connection_pool_test.rb | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index 3f3b98ace0..4173b3ebe6 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -239,7 +239,7 @@ module ActiveRecord synchronize do stale = Time.now - @timeout connections.dup.each do |conn| - remove conn if conn.in_use? && stale > conn.last_use + remove conn if conn.in_use? && stale > conn.last_use && !conn.active? end end end diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb index 015c1c7ce7..3887a4fe96 100644 --- a/activerecord/test/cases/connection_pool_test.rb +++ b/activerecord/test/cases/connection_pool_test.rb @@ -25,7 +25,7 @@ module ActiveRecord @pool.connections.each(&:close) end - def test_reap + def test_reap_and_active @pool.checkout @pool.checkout @pool.checkout @@ -35,9 +35,25 @@ module ActiveRecord @pool.reap + assert_equal connections.length, @pool.connections.length + end + + def test_reap_inactive + @pool.checkout + @pool.checkout + @pool.checkout + @pool.timeout = 0 + + connections = @pool.connections.dup + connections.each do |conn| + conn.extend(Module.new { def active?; false; end; }) + end + + @pool.reap + assert_equal 0, @pool.connections.length ensure - connections.map(&:close) + connections.each(&:close) end def test_remove_connection -- cgit v1.2.3