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:02:48 -0700 |
commit | d7084549b302c1df8ef8ea6a3a22ab491c256eea (patch) | |
tree | 75b6fd600b1455e550aa3f652fe3b6c001cdb3f1 | |
parent | 9823fee7d5579dc4775964e7b6cb6cc6c189aa79 (diff) | |
download | chef-d7084549b302c1df8ef8ea6a3a22ab491c256eea.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 adf180a645..7a180f8edf 100644 --- a/chef/lib/chef/rest.rb +++ b/chef/lib/chef/rest.rb @@ -305,14 +305,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 8a9105c1d6..6b173e324b 100644 --- a/chef/spec/unit/rest_spec.rb +++ b/chef/spec/unit/rest_spec.rb @@ -226,6 +226,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 @@ -234,6 +235,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 @@ -416,6 +418,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) @@ -426,6 +429,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 |