Skip to content

Commit 7779b5e

Browse files
authored
Merge pull request rails#46362 from nycdotnet/connection-pool-docs [ci-skip]
Update ConnectionPool docs
2 parents 2a2a6ab + b00fc77 commit 7779b5e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def async_executor; end
5353
# handle cases in which there are more threads than connections: if all
5454
# connections have been checked out, and a thread tries to checkout a
5555
# connection anyway, then ConnectionPool will wait until some other thread
56-
# has checked in a connection.
56+
# has checked in a connection, or the +checkout_timeout+ has expired.
5757
#
5858
# == Obtaining (checking out) a connection
5959
#
@@ -78,6 +78,12 @@ def async_executor; end
7878
# Connections in the pool are actually AbstractAdapter objects (or objects
7979
# compatible with AbstractAdapter's interface).
8080
#
81+
# While a thread has a connection checked out from the pool using one of the
82+
# above three methods, that connection will automatically be the one used
83+
# by ActiveRecord queries executing on that thread. It is not required to
84+
# explicitly pass the checked out connection to Rails models or queries, for
85+
# example.
86+
#
8187
# == Options
8288
#
8389
# There are several connection-pooling-related options that you can add to
@@ -206,10 +212,15 @@ def release_connection(owner_thread = ActiveSupport::IsolatedExecutionState.cont
206212
end
207213
end
208214

209-
# If a connection obtained through #connection or #with_connection methods
210-
# already exists yield it to the block. If no such connection
211-
# exists checkout a connection, yield it to the block, and checkin the
212-
# connection when finished.
215+
# Yields a connection from the connection pool to the block. If no connection
216+
# is already checked out by the current thread, a connection will be checked
217+
# out from the pool, yielded to the block, and then returned to the pool when
218+
# the block is finished. If a connection has already been checked out on the
219+
# current thread, such as via #connection or #with_connection, that existing
220+
# connection will be the one yielded and it will not be returned to the pool
221+
# automatically at the end of the block; it is expected that such an existing
222+
# connection will be properly returned to the pool by the code that checked
223+
# it out.
213224
def with_connection
214225
unless conn = @thread_cached_conns[connection_cache_key(ActiveSupport::IsolatedExecutionState.context)]
215226
conn = connection

0 commit comments

Comments
 (0)