File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
lib/active_record/connection_adapters/abstract Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -344,8 +344,9 @@ def activated?
344344 # held in a cache keyed by a thread.
345345 def lease_connection
346346 lease = connection_lease
347- lease . sticky = true
348347 lease . connection ||= checkout
348+ lease . sticky = true
349+ lease . connection
349350 end
350351
351352 def permanent_lease? # :nodoc:
Original file line number Diff line number Diff line change @@ -1477,6 +1477,25 @@ def test_inspect_does_not_show_secrets
14771477 pool &.disconnect!
14781478 end
14791479
1480+ def test_checkout_callback_error_does_not_affect_permanent_lease_and_active_connection_state
1481+ checkout_error = StandardError . new ( "error during checkout" )
1482+ proc_to_raise = -> { raise checkout_error }
1483+ ActiveRecord ::ConnectionAdapters ::AbstractAdapter . set_callback ( :checkout , :after , proc_to_raise )
1484+
1485+ assert_predicate @pool , :permanent_lease?
1486+ assert_not_predicate @pool , :active_connection?
1487+
1488+ error = assert_raises StandardError do
1489+ @pool . lease_connection
1490+ end
1491+ assert_same checkout_error , error
1492+
1493+ assert_predicate @pool , :permanent_lease?
1494+ assert_not_predicate @pool , :active_connection?
1495+ ensure
1496+ ActiveRecord ::ConnectionAdapters ::AbstractAdapter . skip_callback ( :checkout , :after , proc_to_raise )
1497+ end
1498+
14801499 private
14811500 def active_connections ( pool )
14821501 pool . connections . find_all ( &:in_use? )
You can’t perform that action at this time.
0 commit comments