diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /lib/gitlab/http.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'lib/gitlab/http.rb')
-rw-r--r-- | lib/gitlab/http.rb | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/lib/gitlab/http.rb b/lib/gitlab/http.rb index 911b71c3734..559e1828a70 100644 --- a/lib/gitlab/http.rb +++ b/lib/gitlab/http.rb @@ -9,32 +9,51 @@ module Gitlab BlockedUrlError = Class.new(StandardError) RedirectionTooDeep = Class.new(StandardError) - HTTP_ERRORS = [ + HTTP_TIMEOUT_ERRORS = [ + Net::OpenTimeout, Net::ReadTimeout, Net::WriteTimeout + ].freeze + HTTP_ERRORS = HTTP_TIMEOUT_ERRORS + [ SocketError, OpenSSL::SSL::SSLError, OpenSSL::OpenSSLError, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, - Net::OpenTimeout, Net::ReadTimeout, Gitlab::HTTP::BlockedUrlError, - Gitlab::HTTP::RedirectionTooDeep + Gitlab::HTTP::BlockedUrlError, Gitlab::HTTP::RedirectionTooDeep ].freeze + DEFAULT_TIMEOUT_OPTIONS = { + open_timeout: 10, + read_timeout: 20, + write_timeout: 30 + }.freeze + include HTTParty # rubocop:disable Gitlab/HTTParty + class << self + alias_method :httparty_perform_request, :perform_request + end + connection_adapter HTTPConnectionAdapter def self.perform_request(http_method, path, options, &block) - super + log_info = options.delete(:extra_log_info) + options_with_timeouts = + if !options.has_key?(:timeout) && Feature.enabled?(:http_default_timeouts) + options.with_defaults(DEFAULT_TIMEOUT_OPTIONS) + else + options + end + + httparty_perform_request(http_method, path, options_with_timeouts, &block) rescue HTTParty::RedirectionTooDeep raise RedirectionTooDeep - end - - def self.try_get(path, options = {}, &block) - log_info = options.delete(:extra_log_info) - self.get(path, options, &block) - rescue *HTTP_ERRORS => e extra_info = log_info || {} extra_info = log_info.call(e, path, options) if log_info.respond_to?(:call) - Gitlab::ErrorTracking.log_exception(e, extra_info) + raise e + end + + def self.try_get(path, options = {}, &block) + self.get(path, options, &block) + rescue *HTTP_ERRORS nil end end |