From: Tom Hughes Date: Wed, 23 Dec 2020 15:24:10 +0000 (+0000) Subject: Merge remote-tracking branch 'upstream/pull/3016' X-Git-Tag: live~2326 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/f4885874f02bc197995dcc32dec1da04a0587791?hp=2519841efe7b89431b146554cc6fce698b4eb15b Merge remote-tracking branch 'upstream/pull/3016' --- diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c1060cbe2..890fcc83c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -58,7 +58,7 @@ Metrics/BlockNesting: # Offense count: 25 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 643 + Max: 644 # Offense count: 68 # Configuration parameters: IgnoredMethods. diff --git a/Gemfile b/Gemfile index 8869fb37c..264674fbc 100644 --- a/Gemfile +++ b/Gemfile @@ -88,9 +88,6 @@ gem "libxml-ruby", ">= 2.0.5", :require => "libxml" gem "htmlentities" gem "sanitize" -# Load SystemTimer for implementing request timeouts -gem "SystemTimer", ">= 1.1.3", :require => "system_timer", :platforms => :ruby_18 - # Load faraday for mockable HTTP client gem "faraday" diff --git a/Gemfile.lock b/Gemfile.lock index 4a9e2e042..b4c92abdf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,6 @@ GEM remote: https://rubygems.org/ specs: - SystemTimer (1.2.3) aasm (5.1.1) concurrent-ruby (~> 1.0) actioncable (6.0.3.4) @@ -468,7 +467,6 @@ PLATFORMS ruby DEPENDENCIES - SystemTimer (>= 1.1.3) aasm actionpack-page_caching (>= 1.2.0) active_record_union diff --git a/app/controllers/api/amf_controller.rb b/app/controllers/api/amf_controller.rb index 5d45eb070..34a8ff7f1 100644 --- a/app/controllers/api/amf_controller.rb +++ b/app/controllers/api/amf_controller.rb @@ -37,6 +37,8 @@ module Api class AmfController < ApiController + require "timeout" + include Potlatch before_action :check_api_writable @@ -130,7 +132,7 @@ module Api def amf_handle_error_with_timeout(call, rootobj, rootid, &block) amf_handle_error(call, rootobj, rootid) do - OSM::Timer.timeout(Settings.api_timeout, OSM::APITimeoutError, &block) + Timeout.timeout(Settings.api_timeout, OSM::APITimeoutError, &block) end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9f2d79eaa..586b18116 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,6 @@ class ApplicationController < ActionController::Base + require "timeout" + include SessionPersistence protect_from_forgery :with => :exception @@ -229,7 +231,7 @@ class ApplicationController < ActionController::Base ## # wrap an api call in a timeout def api_call_timeout(&block) - OSM::Timer.timeout(Settings.api_timeout, Timeout::Error, &block) + Timeout.timeout(Settings.api_timeout, Timeout::Error, &block) rescue Timeout::Error raise OSM::APITimeoutError end @@ -237,7 +239,7 @@ class ApplicationController < ActionController::Base ## # wrap a web page in a timeout def web_timeout(&block) - OSM::Timer.timeout(Settings.web_timeout, Timeout::Error, &block) + Timeout.timeout(Settings.web_timeout, Timeout::Error, &block) rescue ActionView::Template::Error => e e = e.cause diff --git a/lib/nominatim.rb b/lib/nominatim.rb index ffa86d93f..fd0855fc9 100644 --- a/lib/nominatim.rb +++ b/lib/nominatim.rb @@ -1,4 +1,6 @@ module Nominatim + require "timeout" + extend ActionView::Helpers::NumberHelper def self.describe_location(lat, lon, zoom = nil, language = nil) @@ -9,7 +11,7 @@ module Nominatim url = "https://nominatim.openstreetmap.org/reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{language}" begin - response = OSM::Timer.timeout(4) do + response = Timeout.timeout(4) do REXML::Document.new(Net::HTTP.get(URI.parse(url))) end rescue StandardError diff --git a/lib/osm.rb b/lib/osm.rb index daa15fe8b..b6dd64b99 100644 --- a/lib/osm.rb +++ b/lib/osm.rb @@ -5,13 +5,6 @@ module OSM require "rexml/text" require "xml/libxml" - if defined?(SystemTimer) - Timer = SystemTimer - else - require "timeout" - Timer = Timeout - end - # The base class for API Errors. class APIError < RuntimeError def initialize(message = "Generic API Error")