File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
lib/active_record/connection_adapters Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -1221,7 +1221,7 @@ def configure_connection
1221
1221
1222
1222
def attempt_configure_connection
1223
1223
configure_connection
1224
- rescue
1224
+ rescue Exception # Need to handle things such as Timeout::ExitException
1225
1225
disconnect!
1226
1226
raise
1227
1227
end
Original file line number Diff line number Diff line change @@ -894,6 +894,29 @@ def teardown
894
894
connection &.disconnect!
895
895
end
896
896
897
+ test "disconnect and recover on #configure_connection timeout" do
898
+ connection = ActiveRecord ::Base . connection_pool . send ( :new_connection )
899
+
900
+ slow = [ 5 ]
901
+ connection . singleton_class . define_method ( :configure_connection ) do
902
+ if duration = slow . pop
903
+ sleep duration
904
+ end
905
+ super ( )
906
+ end
907
+
908
+ assert_raises Timeout ::Error do
909
+ Timeout . timeout ( 0.2 ) do
910
+ connection . exec_query ( "SELECT 1" )
911
+ end
912
+ end
913
+
914
+ assert_equal [ [ 1 ] ] , connection . exec_query ( "SELECT 1" ) . rows
915
+ assert_empty failures
916
+ ensure
917
+ connection &.disconnect!
918
+ end
919
+
897
920
private
898
921
def raw_transaction_open? ( connection )
899
922
case connection . adapter_name
You can’t perform that action at this time.
0 commit comments