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 1904baaad3c21..1eb98dcabfdc5 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -614,7 +614,7 @@ def checkout_for_exclusive_access(checkout_timeout) msg << " (#{thread_report.join(', ')})" if thread_report.any? - raise ExclusiveConnectionTimeoutError, msg + raise ExclusiveConnectionTimeoutError.new(msg, connection_pool: self) end def with_new_connections_blocked @@ -670,6 +670,8 @@ def acquire_connection(checkout_timeout) reap @available.poll(checkout_timeout) end + rescue ConnectionTimeoutError => ex + raise ex.set_pool(self) end #-- diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb index 01c9c8105ff7a..26a96e2eacd78 100644 --- a/activerecord/test/cases/connection_pool_test.rb +++ b/activerecord/test/cases/connection_pool_test.rb @@ -110,9 +110,10 @@ def test_full_pool_exception @pool.checkout_timeout = 0.001 # no need to delay test suite by waiting the whole full default timeout @pool.size.times { assert @pool.checkout } - assert_raises(ConnectionTimeoutError) do + error = assert_raises(ConnectionTimeoutError) do @pool.checkout end + assert_equal @pool, error.connection_pool end def test_full_pool_blocks @@ -615,9 +616,10 @@ def test_non_bang_disconnect_and_clear_reloadable_connections_throw_exception_if @pool.checkout_timeout = 0.001 # no need to delay test suite by waiting the whole full default timeout [:disconnect, :clear_reloadable_connections].each do |group_action_method| @pool.with_connection do |connection| - assert_raises(ExclusiveConnectionTimeoutError) do + error = assert_raises(ExclusiveConnectionTimeoutError) do new_thread { @pool.public_send(group_action_method) }.join end + assert_equal @pool, error.connection_pool end end ensure