Permalink
Browse files

[CHEF-2164] add retry with backoff for 503s

implemented exponential backoff for 503s. Uses hardcoded 2s base because
5s (current default) is too much, but I don't want to modify the
constant time retry logic used for other types of errors
  • Loading branch information...
1 parent 9390176 commit 02a4eab00c4dd84eac827c7d33b308ac17b58698 @danielsdeleo danielsdeleo committed Apr 2, 2011
Showing with 6 additions and 4 deletions.
  1. +6 −4 chef/lib/chef/rest.rb
View
@@ -298,11 +298,13 @@ def retriable_rest_request(method, url, req_body, headers)
retry
end
raise Timeout::Error, "Timeout connecting to #{url.host}:#{url.port} for #{rest_request.path}, giving up"
- rescue Net::HTTPServerException
- if res.kind_of?(Net::HTTPForbidden)
+ rescue Net::HTTPFatalError => e
+ case e.response
+ when Net::HTTPServiceUnavailable
if http_retry_count - http_attempts + 1 > 0
- Chef::Log.error("Received 403 Forbidden against #{url.host}:#{url.port} for #{rest_request.path}, retry #{http_attempts}/#{http_retry_count}")
- sleep(http_retry_delay)
+ 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
end

0 comments on commit 02a4eab

Please sign in to comment.