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,13 +311,27 @@ class Rietveld(object): ...@@ -311,13 +311,27 @@ class Rietveld(object):
def _send(self, request_path, **kwargs): def _send(self, request_path, **kwargs):
"""Sends a POST/GET to Rietveld. Returns the response body.""" """Sends a POST/GET to Rietveld. Returns the response body."""
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 maxtries = 5
for retry in xrange(maxtries): for retry in xrange(maxtries):
try: try:
logging.debug('%s' % request_path) logging.debug('%s' % request_path)
result = self.rpc_server.Send(request_path, **kwargs) result = self.rpc_server.Send(request_path, **kwargs)
# Sometimes GAE returns a HTTP 200 but with HTTP 500 as the content. How # Sometimes GAE returns a HTTP 200 but with HTTP 500 as the content.
# nice. # How nice.
return result return result
except urllib2.HTTPError, e: except urllib2.HTTPError, e:
if retry >= (maxtries - 1): if retry >= (maxtries - 1):
...@@ -332,6 +346,8 @@ class Rietveld(object): ...@@ -332,6 +346,8 @@ class Rietveld(object):
raise raise
# If reaching this line, loop again. Uses a small backoff. # If reaching this line, loop again. Uses a small backoff.
time.sleep(1+maxtries*2) time.sleep(1+maxtries*2)
finally:
upload.ErrorExit = old_error_exit
# DEPRECATED. # DEPRECATED.
Send = get 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