diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2014-08-23 21:35:57 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2014-08-23 21:35:57 -0700 |
commit | fb58236637095e22f25ed17143e435f4a58d7d6c (patch) | |
tree | cb4cee0bfaeefbef0d180d579ffb0daf1de3c0d3 /lib/chef/http.rb | |
parent | 9f3ca0e4f4fdaae1257117421c99d3e920c9edf0 (diff) | |
download | chef-fb58236637095e22f25ed17143e435f4a58d7d6c.tar.gz |
add retries in additional cases
Diffstat (limited to 'lib/chef/http.rb')
-rw-r--r-- | lib/chef/http.rb | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/chef/http.rb b/lib/chef/http.rb index abc47f636e..bf2316113e 100644 --- a/lib/chef/http.rb +++ b/lib/chef/http.rb @@ -62,7 +62,6 @@ class Chef end - def self.middlewares @middlewares ||= [] end @@ -282,18 +281,34 @@ class Chef end end - # Wraps an HTTP request with retry logic. # === Arguments # url:: URL of the request, used for error messages def retrying_http_errors(url) http_attempts = 0 begin - http_attempts += 1 + loop do + http_attempts += 1 + + response, request, return_value = yield + + if response.kind_of?(Net::HTTPServerError) + if http_retry_count >= http_attempts + Chef::Log.error("Error connecting to #{url} - #{response.code}, retry #{http_attempts}/#{http_retry_count}") + sleep(http_retry_delay) + redo + end + end - yield + return [response, request, return_value] + end rescue SocketError, Errno::ETIMEDOUT => e + if http_retry_count - http_attempts + 1 > 0 + Chef::Log.error("Error connecting to #{url} - #{e.message}, retry #{http_attempts}/#{http_retry_count}") + sleep(http_retry_delay) + retry + end e.message.replace "Error connecting to #{url} - #{e.message}" raise e rescue Errno::ECONNREFUSED @@ -380,7 +395,6 @@ class Chef raise end - public ############################################################################ |