From df9de6fc6c2e950303088500cb4f4660d89a71b6 Mon Sep 17 00:00:00 2001
From: Aaron Patterson <aaron.patterson@gmail.com>
Date: Fri, 30 Dec 2011 11:45:34 -0800
Subject: infinite loop is no longer necessary

---
 .../abstract/connection_pool.rb                    | 31 ++++++++--------------
 1 file changed, 11 insertions(+), 20 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 0d8efa60c2..ee2e419a56 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -186,30 +186,21 @@ module ActiveRecord
       def checkout
         # Checkout an available connection
         synchronize do
-          loop do
-            conn = @connections.find { |c| c.lease }
-
-            unless conn
-              if @connections.size < @size
-                conn = checkout_new_connection
-                conn.lease
-              end
-            end
-
-            if conn
-              checkout_and_verify conn
-              return conn
-            end
+          conn = @connections.find { |c| c.lease }
 
-            if(active_connections.size < @connections.size)
-              next
-            else
-              if @size == active_connections.size
-                raise ConnectionTimeoutError, "could not obtain a database connection#{" within #{@timeout} seconds" if @timeout}. The max pool size is currently #{@size}; consider increasing it."
-              end
+          unless conn
+            if @connections.size < @size
+              conn = checkout_new_connection
+              conn.lease
             end
+          end
 
+          if conn
+            checkout_and_verify conn
+          else
+            raise ConnectionTimeoutError, "could not obtain a database connection#{" within #{@timeout} seconds" if @timeout}. The max pool size is currently #{@size}; consider increasing it."
           end
+
         end
       end
 
-- 
cgit v1.2.3