Permalink
Browse files

connections are only removed if they are inactve

  • Loading branch information...
1 parent 86729eb commit b1ac881433b95498e3b63b2686d1e31f1bdb93fc @tenderlove tenderlove committed Dec 30, 2011
View
2 activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -239,7 +239,7 @@ def reap
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
View
20 activerecord/test/cases/connection_pool_test.rb
@@ -25,7 +25,7 @@ def teardown
@pool.connections.each(&:close)
end
- def test_reap
+ def test_reap_and_active
@pool.checkout
@pool.checkout
@pool.checkout
@@ -35,9 +35,25 @@ def test_reap
@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

0 comments on commit b1ac881

Please sign in to comment.