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 0d8efa60c2953c3d2f60324afad3a9b9b4bb6727..ee2e419a565af342ecde793a18abe70be566e942 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 @@ def clear_stale_cached_connections! 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