Skip to content

Commit

Permalink
Merge pull request rails#49944 from composerinteralia/connectiontimeo…
Browse files Browse the repository at this point in the history
…uterror-pool

Add connection pool to connection timeout errors
  • Loading branch information
jhawthorn authored Nov 7, 2023
2 parents 0157819 + 846bf52 commit e956aaf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -670,6 +670,8 @@ def acquire_connection(checkout_timeout)
reap
@available.poll(checkout_timeout)
end
rescue ConnectionTimeoutError => ex
raise ex.set_pool(self)
end

#--
Expand Down
6 changes: 4 additions & 2 deletions activerecord/test/cases/connection_pool_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e956aaf

Please sign in to comment.