From 474d5ea744474c746beb0187999c23b2be7af5d3 Mon Sep 17 00:00:00 2001 From: Aliaksey Kandratsenka Date: Thu, 2 Oct 2008 22:59:49 +0300 Subject: [PATCH] made ConnectionPool#checkout more robust by trying to loot dead threads when pool is empty --- .../connection_adapters/abstract/connection_pool.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 74381437caff4..b7d7384548244 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -143,7 +143,11 @@ def checkout if @queue.wait(@timeout) next else - raise ConnectionTimeoutError, "could not obtain a database connection within #{@timeout} seconds. The pool size is currently #{@size}, perhaps you need to increase it?" + # try looting dead threads + clear_stale_cached_connections! + if @size == @checked_out.size + raise ConnectionTimeoutError, "could not obtain a database connection within #{@timeout} seconds. The pool size is currently #{@size}, perhaps you need to increase it?" + end end end end