]> git.openstreetmap.org Git - rails.git/commitdiff
Cancel running queries when a timeout occurs
authorTom Hughes <tom@compton.nu>
Wed, 21 Sep 2022 21:47:16 +0000 (22:47 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 21 Sep 2022 21:47:16 +0000 (22:47 +0100)
.rubocop_todo.yml
app/controllers/application_controller.rb

index 2e7bc2f5957977b7faf4c9801f439d1e4f6803dc..240e46c31b9180a8d3a20bd2daf5d98f3c8b1849 100644 (file)
@@ -60,7 +60,7 @@ Metrics/BlockNesting:
 # Offense count: 25
 # Configuration parameters: CountComments, CountAsOne.
 Metrics/ClassLength:
-  Max: 313
+  Max: 316
 
 # Offense count: 58
 # Configuration parameters: IgnoredMethods.
index 1d68654055538fd597265043e2adcb52e3ceb94f..d3f57f0867f819a037b8ddbf581747ddb54f8530 100644 (file)
@@ -231,6 +231,7 @@ class ApplicationController < ActionController::Base
   def api_call_timeout(&block)
     Timeout.timeout(Settings.api_timeout, Timeout::Error, &block)
   rescue Timeout::Error
+    ActiveRecord::Base.connection.raw_connection.cancel
     raise OSM::APITimeoutError
   end
 
@@ -243,11 +244,13 @@ class ApplicationController < ActionController::Base
 
     if e.is_a?(Timeout::Error) ||
        (e.is_a?(ActiveRecord::StatementInvalid) && e.message.include?("execution expired"))
+      ActiveRecord::Base.connection.raw_connection.cancel
       render :action => "timeout"
     else
       raise
     end
   rescue Timeout::Error
+    ActiveRecord::Base.connection.raw_connection.cancel
     render :action => "timeout"
   end