Commit 23be489f authored by Daniel DeLeo's avatar Daniel DeLeo
Browse files

retry all 5xx errors

parent 02a4eab0
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment