instance method
acquire_connection
Ruby on Rails 5.2.8.1
Since v4.0.13 PrivateSignature
acquire_connection(checkout_timeout)
Acquire a connection by one of 1) immediately removing one from the queue of available connections, 2) creating a new connection if the pool is not at capacity, 3) waiting on the queue for a connection to become available.
Raises:
-
ActiveRecord::ConnectionTimeoutError if a connection could not be acquired
Parameters
-
checkout_timeoutreq
Source
# File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 807
def acquire_connection(checkout_timeout)
# NOTE: we rely on <tt>@available.poll</tt> and +try_to_checkout_new_connection+ to
# +conn.lease+ the returned connection (and to do this in a +synchronized+
# section). This is not the cleanest implementation, as ideally we would
# <tt>synchronize { conn.lease }</tt> in this method, but by leaving it to <tt>@available.poll</tt>
# and +try_to_checkout_new_connection+ we can piggyback on +synchronize+ sections
# of the said methods and avoid an additional +synchronize+ overhead.
if conn = @available.poll || try_to_checkout_new_connection
conn
else
reap
@available.poll(checkout_timeout)
end
end
Defined in activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb line 807
· View on GitHub
· Improve this page
· Find usages on GitHub