Skip to content

Commit e956aaf

Browse files
authored
Merge pull request rails#49944 from composerinteralia/connectiontimeouterror-pool
Add connection pool to connection timeout errors
2 parents 0157819 + 846bf52 commit e956aaf

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ def checkout_for_exclusive_access(checkout_timeout)
614614

615615
msg << " (#{thread_report.join(', ')})" if thread_report.any?
616616

617-
raise ExclusiveConnectionTimeoutError, msg
617+
raise ExclusiveConnectionTimeoutError.new(msg, connection_pool: self)
618618
end
619619

620620
def with_new_connections_blocked
@@ -670,6 +670,8 @@ def acquire_connection(checkout_timeout)
670670
reap
671671
@available.poll(checkout_timeout)
672672
end
673+
rescue ConnectionTimeoutError => ex
674+
raise ex.set_pool(self)
673675
end
674676

675677
#--

activerecord/test/cases/connection_pool_test.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ def test_full_pool_exception
110110
@pool.checkout_timeout = 0.001 # no need to delay test suite by waiting the whole full default timeout
111111
@pool.size.times { assert @pool.checkout }
112112

113-
assert_raises(ConnectionTimeoutError) do
113+
error = assert_raises(ConnectionTimeoutError) do
114114
@pool.checkout
115115
end
116+
assert_equal @pool, error.connection_pool
116117
end
117118

118119
def test_full_pool_blocks
@@ -615,9 +616,10 @@ def test_non_bang_disconnect_and_clear_reloadable_connections_throw_exception_if
615616
@pool.checkout_timeout = 0.001 # no need to delay test suite by waiting the whole full default timeout
616617
[:disconnect, :clear_reloadable_connections].each do |group_action_method|
617618
@pool.with_connection do |connection|
618-
assert_raises(ExclusiveConnectionTimeoutError) do
619+
error = assert_raises(ExclusiveConnectionTimeoutError) do
619620
new_thread { @pool.public_send(group_action_method) }.join
620621
end
622+
assert_equal @pool, error.connection_pool
621623
end
622624
end
623625
ensure

0 commit comments

Comments
 (0)