aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb11
1 files changed, 6 insertions, 5 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 ee2e419a56..b548412644 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -186,13 +186,14 @@ module ActiveRecord
def checkout
# Checkout an available connection
synchronize do
+ # Try to find a connection that hasn't been leased
conn = @connections.find { |c| c.lease }
- unless conn
- if @connections.size < @size
- conn = checkout_new_connection
- conn.lease
- end
+ # If all connections were leased, and we have room to expand,
+ # create a new connection and lease it.
+ if !conn && @connections.size < @size
+ conn = checkout_new_connection
+ conn.lease
end
if conn