Commit a01fd324 authored by maruel@chromium.org's avatar maruel@chromium.org

Convert ErrorExit() calls back into an HTTPError exception so it can be properly handled.

Occasionally, AppEngine throws HTTP 500. In practice it's not a big deal but
upload.py converts them into sys.exit() call which is problematic. This breaks
the commit queue since this behaviors forces the CQ to quit.

R=dpranke@chromium.org
BUG=
TEST=


Review URL: http://codereview.chromium.org/9480005

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@123775 0039d316-1c4b-4281-b951-d872f2087c98
parent ffcc161f
......@@ -311,27 +311,43 @@ class Rietveld(object):
def _send(self, request_path, **kwargs):
"""Sends a POST/GET to Rietveld. Returns the response body."""
maxtries = 5
for retry in xrange(maxtries):
try:
logging.debug('%s' % request_path)
result = self.rpc_server.Send(request_path, **kwargs)
# Sometimes GAE returns a HTTP 200 but with HTTP 500 as the content. How
# nice.
return result
except urllib2.HTTPError, e:
if retry >= (maxtries - 1):
raise
if e.code not in (500, 502, 503):
raise
except urllib2.URLError, e:
if retry >= (maxtries - 1):
raise
if not 'Name or service not known' in e.reason:
# Usually internal GAE flakiness.
raise
# If reaching this line, loop again. Uses a small backoff.
time.sleep(1+maxtries*2)
try:
# Sadly, upload.py calls ErrorExit() which does a sys.exit(1) on HTTP
# 500 in AbstractRpcServer.Send().
old_error_exit = upload.ErrorExit
def trap_http_500(msg):
"""Converts an incorrect ErrorExit() call into a HTTPError exception."""
m = re.search(r'(50\d) Server Error', msg)
if m:
# Fake an HTTPError exception. Cheezy. :(
raise urllib2.HTTPError(
request_path, m.group(1), e.args[0], None, None)
old_error_exit(msg)
upload.ErrorExit = trap_http_500
maxtries = 5
for retry in xrange(maxtries):
try:
logging.debug('%s' % request_path)
result = self.rpc_server.Send(request_path, **kwargs)
# Sometimes GAE returns a HTTP 200 but with HTTP 500 as the content.
# How nice.
return result
except urllib2.HTTPError, e:
if retry >= (maxtries - 1):
raise
if e.code not in (500, 502, 503):
raise
except urllib2.URLError, e:
if retry >= (maxtries - 1):
raise
if not 'Name or service not known' in e.reason:
# Usually internal GAE flakiness.
raise
# If reaching this line, loop again. Uses a small backoff.
time.sleep(1+maxtries*2)
finally:
upload.ErrorExit = old_error_exit
# DEPRECATED.
Send = get
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