mirror of
https://github.com/flatcar/scripts.git
synced 2025-11-24 20:11:59 +01:00
Retry in parallel_emerge for 5xx error codes.
When the server returns a 5xx error code, we should retry. Such errors are often due to flakiness, so retries resolve the issue. BUG=chromium-os:9217 TEST=Tested parallel_emerge with fake URL to verify it retries. Change-Id: Ie5cf003562b5261005be9929624769394b4802a1 Review URL: http://codereview.chromium.org/5056003
This commit is contained in:
parent
b593c39e9d
commit
8ce0100b03
@ -667,9 +667,10 @@ class DepGraphGenerator(object):
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
def retry_urlopen(url, tries=3):
|
def retry_urlopen(url, tries=3):
|
||||||
"""Open the specified url, retrying if we run into network errors.
|
"""Open the specified url, retrying if we run into temporary errors.
|
||||||
|
|
||||||
We do not retry for HTTP errors.
|
We retry for both network errors and 5xx Server Errors. We do not retry
|
||||||
|
for HTTP errors with a non-5xx code.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
url: The specified url.
|
url: The specified url.
|
||||||
@ -682,12 +683,17 @@ class DepGraphGenerator(object):
|
|||||||
try:
|
try:
|
||||||
return urllib2.urlopen(url)
|
return urllib2.urlopen(url)
|
||||||
except urllib2.HTTPError as e:
|
except urllib2.HTTPError as e:
|
||||||
raise
|
if i + 1 >= tries or e.code < 500:
|
||||||
except urllib2.URLError as e:
|
|
||||||
if i + 1 == tries:
|
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
print "Cannot GET %s: %s" % (url, e)
|
print "Cannot GET %s: %s" % (url, str(e))
|
||||||
|
except urllib2.URLError as e:
|
||||||
|
if i + 1 >= tries:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
print "Cannot GET %s: %s" % (url, str(e))
|
||||||
|
print "Sleeping for 10 seconds before retrying..."
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
url = os.path.join(binhost_url, "Packages")
|
url = os.path.join(binhost_url, "Packages")
|
||||||
try:
|
try:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user