Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 370 lines (330 sloc) 13.423 kB
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
1 require 'monitor'
50cd4bd @nicksieger Introduce synchronization around connection pool access
nicksieger authored
2 require 'set'
e8550ee @jeremy Cherry-pick core extensions
jeremy authored
3 require 'active_support/core_ext/module/synchronization'
50cd4bd @nicksieger Introduce synchronization around connection pool access
nicksieger authored
4
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
5 module ActiveRecord
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
6 # Raised when a connection could not be obtained within the connection
7 # acquisition timeout period.
8 class ConnectionTimeoutError < ConnectionNotEstablished
9 end
10
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
11 module ConnectionAdapters
f17159b @fxn edit pass: the names of Rails components have a space, ie, "Active Re…
fxn authored
12 # Connection pool base class for managing Active Record database
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
13 # connections.
14 #
a293278 @lifo Merge docrails
lifo authored
15 # == Introduction
16 #
17 # A connection pool synchronizes thread access to a limited number of
18 # database connections. The basic idea is that each thread checks out a
19 # database connection from the pool, uses that connection, and checks the
20 # connection back in. ConnectionPool is completely thread-safe, and will
21 # ensure that a connection cannot be used by two threads at the same time,
22 # as long as ConnectionPool's contract is correctly followed. It will also
23 # handle cases in which there are more threads than connections: if all
24 # connections have been checked out, and a thread tries to checkout a
25 # connection anyway, then ConnectionPool will wait until some other thread
26 # has checked in a connection.
27 #
28 # == Obtaining (checking out) a connection
29 #
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
30 # Connections can be obtained and used from a connection pool in several
31 # ways:
32 #
f17159b @fxn edit pass: the names of Rails components have a space, ie, "Active Re…
fxn authored
33 # 1. Simply use ActiveRecord::Base.connection as with Active Record 2.1 and
817a07b @nicksieger More doco and class/method renames. Now have a strategy for integrati…
nicksieger authored
34 # earlier (pre-connection-pooling). Eventually, when you're done with
35 # the connection(s) and wish it to be returned to the pool, you call
36 # ActiveRecord::Base.clear_active_connections!. This will be the
f17159b @fxn edit pass: the names of Rails components have a space, ie, "Active Re…
fxn authored
37 # default behavior for Active Record when used in conjunction with
38 # Action Pack's request handling cycle.
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
39 # 2. Manually check out a connection from the pool with
40 # ActiveRecord::Base.connection_pool.checkout. You are responsible for
41 # returning this connection to the pool when finished by calling
42 # ActiveRecord::Base.connection_pool.checkin(connection).
43 # 3. Use ActiveRecord::Base.connection_pool.with_connection(&block), which
44 # obtains a connection, yields it as the sole argument to the block,
45 # and returns it to the pool after the block completes.
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
46 #
a293278 @lifo Merge docrails
lifo authored
47 # Connections in the pool are actually AbstractAdapter objects (or objects
48 # compatible with AbstractAdapter's interface).
49 #
50 # == Options
51 #
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
52 # There are two connection-pooling-related options that you can add to
53 # your database connection configuration:
54 #
55 # * +pool+: number indicating size of connection pool (default 5)
56 # * +wait_timeout+: number of seconds to block and wait for a connection
57 # before giving up and raising a timeout error (default 5 seconds).
817a07b @nicksieger More doco and class/method renames. Now have a strategy for integrati…
nicksieger authored
58 class ConnectionPool
cccb998 @josevalim Expose connections available in the connection pool.
josevalim authored
59 attr_reader :spec, :connections
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
60
a293278 @lifo Merge docrails
lifo authored
61 # Creates a new ConnectionPool object. +spec+ is a ConnectionSpecification
62 # object which describes database connection information (e.g. adapter,
63 # host name, username, password, etc), as well as the maximum size for
64 # this ConnectionPool.
65 #
66 # The default ConnectionPool maximum size is 5.
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
67 def initialize(spec)
68 @spec = spec
dd77733 @jeremy Timeout the connection pool monitor on ruby 1.8 only
jeremy authored
69
029952e @nicksieger Extract a base class for connection pools, start to flesh out reserve…
nicksieger authored
70 # The cache of reserved connections mapped to threads
71 @reserved_connections = {}
dd77733 @jeremy Timeout the connection pool monitor on ruby 1.8 only
jeremy authored
72
cab76ce @nicksieger Add synchronization to connection pool also
nicksieger authored
73 # The mutex used to synchronize pool access
74 @connection_mutex = Monitor.new
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
75 @queue = @connection_mutex.new_cond
dd77733 @jeremy Timeout the connection pool monitor on ruby 1.8 only
jeremy authored
76
77 # default 5 second timeout unless on ruby 1.9
78 @timeout =
79 if RUBY_VERSION < '1.9'
80 spec.config[:wait_timeout] || 5
81 end
82
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
83 # default max pool size to 5
84 @size = (spec.config[:pool] && spec.config[:pool].to_i) || 5
dd77733 @jeremy Timeout the connection pool monitor on ruby 1.8 only
jeremy authored
85
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
86 @connections = []
87 @checked_out = []
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
88 end
89
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
90 # Retrieve the connection associated with the current thread, or call
91 # #checkout to obtain one if necessary.
92 #
93 # #connection can be called any number of times; the connection is
94 # held in a hash keyed by the thread id.
95 def connection
d07a6b1 @nicksieger Make clear_active_connections! also return stale connections back to …
nicksieger authored
96 if conn = @reserved_connections[current_connection_id]
029952e @nicksieger Extract a base class for connection pools, start to flesh out reserve…
nicksieger authored
97 conn
98 else
d07a6b1 @nicksieger Make clear_active_connections! also return stale connections back to …
nicksieger authored
99 @reserved_connections[current_connection_id] = checkout
029952e @nicksieger Extract a base class for connection pools, start to flesh out reserve…
nicksieger authored
100 end
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
101 end
102
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
103 # Signal that the thread is finished with the current connection.
817a07b @nicksieger More doco and class/method renames. Now have a strategy for integrati…
nicksieger authored
104 # #release_connection releases the connection-thread association
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
105 # and returns the connection to the pool.
3344520 @tenderlove reduce the number of times current_connection_id is called in with_co…
tenderlove authored
106 def release_connection(with_id = current_connection_id)
107 conn = @reserved_connections.delete(with_id)
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
108 checkin conn if conn
109 end
110
5501b99 @coderrr Ensure ActiveRecord::Base.connection_pool.with_connection creates a n…
coderrr authored
111 # If a connection already exists yield it to the block. If no connection
112 # exists checkout a connection, yield it to the block, and checkin the
113 # connection when finished.
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
114 def with_connection
3344520 @tenderlove reduce the number of times current_connection_id is called in with_co…
tenderlove authored
115 connection_id = current_connection_id
116 fresh_connection = true unless @reserved_connections[connection_id]
5501b99 @coderrr Ensure ActiveRecord::Base.connection_pool.with_connection creates a n…
coderrr authored
117 yield connection
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
118 ensure
3344520 @tenderlove reduce the number of times current_connection_id is called in with_co…
tenderlove authored
119 release_connection(connection_id) if fresh_connection
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
120 end
121
029952e @nicksieger Extract a base class for connection pools, start to flesh out reserve…
nicksieger authored
122 # Returns true if a connection has already been opened.
123 def connected?
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
124 !@connections.empty?
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
125 end
126
a293278 @lifo Merge docrails
lifo authored
127 # Disconnects all connections in the pool, and clears the pool.
029952e @nicksieger Extract a base class for connection pools, start to flesh out reserve…
nicksieger authored
128 def disconnect!
129 @reserved_connections.each do |name,conn|
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
130 checkin conn
029952e @nicksieger Extract a base class for connection pools, start to flesh out reserve…
nicksieger authored
131 end
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
132 @reserved_connections = {}
133 @connections.each do |conn|
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
134 conn.disconnect!
135 end
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
136 @connections = []
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
137 end
138
50cd4bd @nicksieger Introduce synchronization around connection pool access
nicksieger authored
139 # Clears the cache which maps classes
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
140 def clear_reloadable_connections!
029952e @nicksieger Extract a base class for connection pools, start to flesh out reserve…
nicksieger authored
141 @reserved_connections.each do |name, conn|
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
142 checkin conn
029952e @nicksieger Extract a base class for connection pools, start to flesh out reserve…
nicksieger authored
143 end
144 @reserved_connections = {}
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
145 @connections.each do |conn|
146 conn.disconnect! if conn.requires_reloading?
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
147 end
62c4e4d @ebeigarts Fix connection reloading in development mode. [#4929 state:resolved]
ebeigarts authored
148 @connections.delete_if do |conn|
149 conn.requires_reloading?
150 end
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
151 end
152
817a07b @nicksieger More doco and class/method renames. Now have a strategy for integrati…
nicksieger authored
153 # Verify active connections and remove and disconnect connections
154 # associated with stale threads.
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
155 def verify_active_connections! #:nodoc:
d07a6b1 @nicksieger Make clear_active_connections! also return stale connections back to …
nicksieger authored
156 clear_stale_cached_connections!
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
157 @connections.each do |connection|
7ba2872 @nicksieger Deprecate verification_timeout and verify before reset
nicksieger authored
158 connection.verify!
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
159 end
160 end
161
d07a6b1 @nicksieger Make clear_active_connections! also return stale connections back to …
nicksieger authored
162 # Return any checked-out connections back to the pool by threads that
163 # are no longer alive.
164 def clear_stale_cached_connections!
42be67e @tenderlove unfactoring clear_stale_cached_connections!
tenderlove authored
165 keys = @reserved_connections.keys - Thread.list.find_all { |t|
166 t.alive?
167 }.map { |thread| thread.object_id }
168
169 keys.each do |key|
170 checkin @reserved_connections[key]
171 @reserved_connections.delete(key)
d07a6b1 @nicksieger Make clear_active_connections! also return stale connections back to …
nicksieger authored
172 end
173 end
174
a293278 @lifo Merge docrails
lifo authored
175 # Check-out a database connection from the pool, indicating that you want
176 # to use it. You should call #checkin when you no longer need this.
177 #
178 # This is done by either returning an existing connection, or by creating
179 # a new connection. If the maximum number of connections for this pool has
180 # already been reached, but the pool is empty (i.e. they're all being used),
181 # then this method will wait until a thread has checked in a connection.
182 # The wait time is bounded however: if no connection can be checked out
183 # within the timeout specified for this pool, then a ConnectionTimeoutError
184 # exception will be raised.
185 #
186 # Returns: an AbstractAdapter object.
187 #
188 # Raises:
189 # - ConnectionTimeoutError: no connection can be obtained from the pool
190 # within the timeout period.
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
191 def checkout
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
192 # Checkout an available connection
193 @connection_mutex.synchronize do
21eb18a @alk Fix race in ConnectionPool#checkout
alk authored
194 loop do
195 conn = if @checked_out.size < @connections.size
196 checkout_existing_connection
197 elsif @connections.size < @size
198 checkout_new_connection
199 end
200 return conn if conn
201 # No connections available; wait for one
202 if @queue.wait(@timeout)
203 next
204 else
8343611 @alk made ConnectionPool#checkout more robust by trying to loot dead threa…
alk authored
205 # try looting dead threads
206 clear_stale_cached_connections!
207 if @size == @checked_out.size
dd77733 @jeremy Timeout the connection pool monitor on ruby 1.8 only
jeremy authored
208 raise ConnectionTimeoutError, "could not obtain a database connection#{" within #{@timeout} seconds" if @timeout}. The max pool size is currently #{@size}; consider increasing it."
8343611 @alk made ConnectionPool#checkout more robust by trying to loot dead threa…
alk authored
209 end
21eb18a @alk Fix race in ConnectionPool#checkout
alk authored
210 end
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
211 end
212 end
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
213 end
214
a293278 @lifo Merge docrails
lifo authored
215 # Check-in a database connection back into the pool, indicating that you
216 # no longer need this connection.
217 #
218 # +conn+: an AbstractAdapter object, which was obtained by earlier by
219 # calling +checkout+ on this pool.
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
220 def checkin(conn)
221 @connection_mutex.synchronize do
a260e02 @wycats Whoops. _run_*_callbacks is private
wycats authored
222 conn.send(:_run_checkin_callbacks) do
471a394 @nicksieger Modify connection pool callbacks to be compatible w/ new style
nicksieger authored
223 @checked_out.delete conn
224 @queue.signal
225 end
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
226 end
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
227 end
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
228
113cc4e @nicksieger Remove some synchronization that's probably overkill, assuming one do…
nicksieger authored
229 synchronize :clear_reloadable_connections!, :verify_active_connections!,
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
230 :connected?, :disconnect!, :with => :@connection_mutex
231
232 private
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
233 def new_connection
a3f12f5 @nicksieger Default connection allow_concurrency to false (for PostgreSQL)
nicksieger authored
234 ActiveRecord::Base.send(spec.adapter_method, spec.config)
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
235 end
236
d07a6b1 @nicksieger Make clear_active_connections! also return stale connections back to …
nicksieger authored
237 def current_connection_id #:nodoc:
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
238 Thread.current.object_id
239 end
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
240
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
241 def checkout_new_connection
242 c = new_connection
243 @connections << c
a96b7d4 @nicksieger Add connection reset and verification upon each connection checkout
nicksieger authored
244 checkout_and_verify(c)
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
245 end
246
247 def checkout_existing_connection
d7d2d73 @nicksieger Fix typo: was using brackets instead of parens. Must need more sleep.
nicksieger authored
248 c = (@connections - @checked_out).first
a96b7d4 @nicksieger Add connection reset and verification upon each connection checkout
nicksieger authored
249 checkout_and_verify(c)
250 end
251
252 def checkout_and_verify(c)
471a394 @nicksieger Modify connection pool callbacks to be compatible w/ new style
nicksieger authored
253 c.run_callbacks :checkout do
254 c.verify!
255 @checked_out << c
256 end
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
257 c
258 end
259 end
260
a293278 @lifo Merge docrails
lifo authored
261 # ConnectionHandler is a collection of ConnectionPool objects. It is used
f17159b @fxn edit pass: the names of Rails components have a space, ie, "Active Re…
fxn authored
262 # for keeping separate connection pools for Active Record models that connect
a293278 @lifo Merge docrails
lifo authored
263 # to different databases.
264 #
265 # For example, suppose that you have 5 models, with the following hierarchy:
266 #
267 # |
268 # +-- Book
269 # | |
270 # | +-- ScaryBook
271 # | +-- GoodBook
272 # +-- Author
273 # +-- BankAccount
274 #
275 # Suppose that Book is to connect to a separate database (i.e. one other
276 # than the default database). Then Book, ScaryBook and GoodBook will all use
277 # the same connection pool. Likewise, Author and BankAccount will use the
278 # same connection pool. However, the connection pool used by Author/BankAccount
279 # is not the same as the one used by Book/ScaryBook/GoodBook.
280 #
281 # Normally there is only a single ConnectionHandler instance, accessible via
f17159b @fxn edit pass: the names of Rails components have a space, ie, "Active Re…
fxn authored
282 # ActiveRecord::Base.connection_handler. Active Record models use this to
a293278 @lifo Merge docrails
lifo authored
283 # determine that connection pool that they should use.
ca6d717 @nicksieger Deprecate allow_concurrency and make it have no effect
nicksieger authored
284 class ConnectionHandler
b952470 @tenderlove use an attr_reader for performance
tenderlove authored
285 attr_reader :connection_pools
286
72d959d @nicksieger Split connection handler into single- and multiple-thread versions.
nicksieger authored
287 def initialize(pools = {})
288 @connection_pools = pools
289 end
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
290
291 def establish_connection(name, spec)
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
292 @connection_pools[name] = ConnectionAdapters::ConnectionPool.new(spec)
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
293 end
294
d07a6b1 @nicksieger Make clear_active_connections! also return stale connections back to …
nicksieger authored
295 # Returns any connections in use by the current thread back to the pool,
296 # and also returns connections to the pool cached by threads that are no
297 # longer alive.
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
298 def clear_active_connections!
529c271 @nicksieger Simplify dispatcher callbacks to eliminate unnecessary stale thread p…
nicksieger authored
299 @connection_pools.each_value {|pool| pool.release_connection }
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
300 end
301
302 # Clears the cache which maps classes
303 def clear_reloadable_connections!
304 @connection_pools.each_value {|pool| pool.clear_reloadable_connections! }
305 end
306
307 def clear_all_connections!
72d959d @nicksieger Split connection handler into single- and multiple-thread versions.
nicksieger authored
308 @connection_pools.each_value {|pool| pool.disconnect! }
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
309 end
310
311 # Verify active connections.
312 def verify_active_connections! #:nodoc:
817a07b @nicksieger More doco and class/method renames. Now have a strategy for integrati…
nicksieger authored
313 @connection_pools.each_value {|pool| pool.verify_active_connections! }
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
314 end
315
316 # Locate the connection of the nearest super class. This can be an
317 # active or defined connection: if it is the latter, it will be
318 # opened and set as the active connection for the class it was defined
319 # for (not necessarily the current class).
320 def retrieve_connection(klass) #:nodoc:
321 pool = retrieve_connection_pool(klass)
322 (pool && pool.connection) or raise ConnectionNotEstablished
323 end
324
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
325 # Returns true if a connection that's accessible to this class has
326 # already been opened.
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
327 def connected?(klass)
0832bc6 @lifo Make sure ActiveRecord::Base.connected? doesn't raise an exception fo…
lifo authored
328 conn = retrieve_connection_pool(klass)
329 conn ? conn.connected? : false
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
330 end
331
332 # Remove the connection for this class. This will close the active
333 # connection and the defined connection (if they exist). The result
334 # can be used as an argument for establish_connection, for easily
335 # re-establishing the connection.
336 def remove_connection(klass)
337 pool = @connection_pools[klass.name]
04ef434 @tenderlove only test for existence of +pool+ once
tenderlove authored
338 return nil unless pool
339
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
340 @connection_pools.delete_if { |key, value| value == pool }
04ef434 @tenderlove only test for existence of +pool+ once
tenderlove authored
341 pool.disconnect!
342 pool.spec.config
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
343 end
344
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
345 def retrieve_connection_pool(klass)
3007545 @nicksieger Minor tweak to retrieve_connection_pool -- recurse instead of loop
nicksieger authored
346 pool = @connection_pools[klass.name]
347 return pool if pool
348 return nil if ActiveRecord::Base == klass
349 retrieve_connection_pool klass.superclass
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
350 end
72d959d @nicksieger Split connection handler into single- and multiple-thread versions.
nicksieger authored
351 end
1b22071 @josh Ensure ActiveRecord session store's connections are checked in after …
josh authored
352
353 class ConnectionManagement
354 def initialize(app)
355 @app = app
356 end
357
358 def call(env)
359 @app.call(env)
360 ensure
e033b5d @lifo Merge docrails
lifo authored
361 # Don't return connection (and perform implicit rollback) if
1b22071 @josh Ensure ActiveRecord session store's connections are checked in after …
josh authored
362 # this request is a part of integration test
363 unless env.key?("rack.test")
364 ActiveRecord::Base.clear_active_connections!
365 end
366 end
367 end
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
368 end
21eb18a @alk Fix race in ConnectionPool#checkout
alk authored
369 end
Something went wrong with that request. Please try again.