diff options
author | Daniel DeLeo <dan@opscode.com> | 2011-04-11 17:02:48 -0700 |
---|---|---|
committer | Daniel DeLeo <dan@opscode.com> | 2011-04-11 17:03:34 -0700 |
commit | 23be489f44191f0ccbd1b460df75176553f8f9b9 (patch) | |
tree | 40476ea191021eea68e3b8640967573253563347 | |
parent | 02a4eab00c4dd84eac827c7d33b308ac17b58698 (diff) | |
download | chef-23be489f44191f0ccbd1b460df75176553f8f9b9.tar.gz |
retry all 5xx errors
-rw-r--r-- | chef/lib/chef/rest.rb | 13 | ||||
-rw-r--r-- | chef/spec/unit/rest_spec.rb | 4 |
2 files changed, 9 insertions, 8 deletions
diff --git a/chef/lib/chef/rest.rb b/chef/lib/chef/rest.rb index 47273db588..cb3e298e8c 100644 --- a/chef/lib/chef/rest.rb +++ b/chef/lib/chef/rest.rb @@ -299,14 +299,11 @@ class Chef end raise Timeout::Error, "Timeout connecting to #{url.host}:#{url.port} for #{rest_request.path}, giving up" rescue Net::HTTPFatalError => e - case e.response - when Net::HTTPServiceUnavailable - if http_retry_count - http_attempts + 1 > 0 - sleep_time = 1 + (2 ** http_attempts) + rand(2 ** http_attempts) - Chef::Log.error("Service Unavailable for #{url}, retrying #{http_attempts}/#{http_retry_count} in #{sleep_time}s") - sleep(sleep_time) - retry - end + if http_retry_count - http_attempts + 1 > 0 + sleep_time = 1 + (2 ** http_attempts) + rand(2 ** http_attempts) + Chef::Log.error("Server returned error for #{url}, retrying #{http_attempts}/#{http_retry_count} in #{sleep_time}s") + sleep(sleep_time) + retry end raise end diff --git a/chef/spec/unit/rest_spec.rb b/chef/spec/unit/rest_spec.rb index ccebb82ca4..c6c5709127 100644 --- a/chef/spec/unit/rest_spec.rb +++ b/chef/spec/unit/rest_spec.rb @@ -231,6 +231,7 @@ describe Chef::REST do http_response.stub!(:body).and_return('{ "error":[ "Ears get sore!", "Not even four" ] }') http_response.stub!(:read_body) @http_client.stub!(:request).and_yield(http_response).and_return(http_response) + @rest.stub!(:sleep) lambda {@rest.run_request(:GET, @url)}.should raise_error(Net::HTTPFatalError) @log_stringio.string.should match(Regexp.escape('WARN -- : HTTP Request Returned 500 drooling from inside of mouth: Ears get sore!, Not even four')) end @@ -239,6 +240,7 @@ describe Chef::REST do @http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth") http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth") http_response.stub!(:read_body) + @rest.stub!(:sleep) @http_client.stub!(:request).and_yield(http_response).and_return(http_response) lambda {@rest.run_request(:GET, @url)}.should raise_error(Net::HTTPFatalError) end @@ -404,6 +406,7 @@ describe Chef::REST do http_response.add_field("content-type", "application/json") http_response.stub!(:body).and_return('{ "error":[ "Ears get sore!", "Not even four" ] }') http_response.stub!(:read_body) + @rest.stub!(:sleep) @http_client.stub!(:request).and_yield(http_response).and_return(http_response) lambda {@rest.run_request(:GET, @url)}.should raise_error(Net::HTTPFatalError) @@ -414,6 +417,7 @@ describe Chef::REST do http_response = Net::HTTPServerError.new("1.1", "500", "drooling from inside of mouth") http_response.stub!(:body) http_response.stub!(:read_body) + @rest.stub!(:sleep) @http_client.stub!(:request).and_yield(http_response).and_return(http_response) lambda {@rest.api_request(:GET, @url)}.should raise_error(Net::HTTPFatalError) end |