diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-09-11 14:29:07 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-09-11 14:29:07 -0700 |
commit | b4b5971ff73f3191be03644fa0c9951a930717d2 (patch) | |
tree | 417a326bece050159d024e601326a4283be2b4bd /activerecord | |
parent | f2a44ade14f995d0574bedf79c8d1bee520f0306 (diff) | |
parent | 5b7cfc5eeae3c5aa8e2ab5e3a0b9bd63b8465168 (diff) | |
download | rails-b4b5971ff73f3191be03644fa0c9951a930717d2.tar.gz rails-b4b5971ff73f3191be03644fa0c9951a930717d2.tar.bz2 rails-b4b5971ff73f3191be03644fa0c9951a930717d2.zip |
Merge pull request #7601 from jrochkind/connection_pool_unify_exceptions
ConnectionPool, unify exceptions, ConnectionTimeoutError
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 28 | ||||
-rw-r--r-- | activerecord/test/cases/connection_pool_test.rb | 2 |
2 files changed, 12 insertions, 18 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 bf08459b3b..d0ef20f1eb 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -5,14 +5,11 @@ require 'active_support/core_ext/module/deprecation' module ActiveRecord # Raised when a connection could not be obtained within the connection - # acquisition timeout period. + # acquisition timeout period: because max connections in pool + # are in use. class ConnectionTimeoutError < ConnectionNotEstablished end - # Raised when a connection pool is full and another connection is requested - class PoolFullError < ConnectionNotEstablished - end - module ConnectionAdapters # Connection pool base class for managing Active Record database # connections. @@ -187,7 +184,11 @@ module ActiveRecord return remove if any? elapsed = Time.now - t0 - raise ConnectionTimeoutError if elapsed >= timeout + if elapsed >= timeout + msg = 'could not obtain a database connection within %0.3f seconds (waited %0.3f seconds)' % + [timeout, elapsed] + raise ConnectionTimeoutError, msg + end end ensure @num_waiting -= 1 @@ -350,12 +351,12 @@ module ActiveRecord # # If all connections are leased and the pool is at capacity (meaning the # number of currently leased connections is greater than or equal to the - # size limit set), an ActiveRecord::PoolFullError exception will be raised. + # size limit set), an ActiveRecord::ConnectionTimeoutError exception will be raised. # # Returns: an AbstractAdapter object. # # Raises: - # - PoolFullError: no connection can be obtained from the pool. + # - ConnectionTimeoutError: no connection can be obtained from the pool. def checkout synchronize do conn = acquire_connection @@ -416,8 +417,7 @@ module ActiveRecord # queue for a connection to become available. # # Raises: - # - PoolFullError if a connection could not be acquired (FIXME: - # why not ConnectionTimeoutError? + # - ConnectionTimeoutError if a connection could not be acquired def acquire_connection if conn = @available.poll conn @@ -425,13 +425,7 @@ module ActiveRecord checkout_new_connection else t0 = Time.now - begin - @available.poll(@checkout_timeout) - rescue ConnectionTimeoutError - msg = 'could not obtain a database connection within %0.3f seconds (waited %0.3f seconds)' % - [@checkout_timeout, Time.now - t0] - raise PoolFullError, msg - end + @available.poll(@checkout_timeout) end end diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb index 8287b35aaf..0718d0886f 100644 --- a/activerecord/test/cases/connection_pool_test.rb +++ b/activerecord/test/cases/connection_pool_test.rb @@ -89,7 +89,7 @@ module ActiveRecord end def test_full_pool_exception - assert_raises(PoolFullError) do + assert_raises(ConnectionTimeoutError) do (@pool.size + 1).times do @pool.checkout end |