From 09263bc4a1943a7e6bc8e50128b4667a66653cda Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 21 Sep 2022 22:47:16 +0100 Subject: [PATCH] Cancel running queries when a timeout occurs --- .rubocop_todo.yml | 2 +- app/controllers/application_controller.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2e7bc2f59..240e46c31 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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. diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1d6865405..d3f57f086 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 -- 2.39.5