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