Internal Client should only retry server errors

Change-Id: I0a3f4a01d50b6a5d5528f527faa34573c7dde619
This commit is contained in:
Clay Gerrard 2018-01-18 18:33:08 -08:00
parent cd2c73fd95
commit cbcbc77468
2 changed files with 5 additions and 11 deletions

View File

@ -26,11 +26,10 @@ from time import gmtime, strftime, time
from zlib import compressobj
from swift.common.exceptions import ClientException
from swift.common.http import HTTP_NOT_FOUND, HTTP_MULTIPLE_CHOICES, \
HTTP_CONFLICT
from swift.common.http import (HTTP_NOT_FOUND, HTTP_MULTIPLE_CHOICES,
is_server_error)
from swift.common.swob import Request
from swift.common.utils import quote, closing_if_possible, \
server_handled_successfully
from swift.common.utils import quote, closing_if_possible
from swift.common.wsgi import loadapp, pipeline_property
if six.PY3:
@ -199,14 +198,9 @@ class InternalClient(object):
if resp.status_int in acceptable_statuses or \
resp.status_int // 100 in acceptable_statuses:
return resp
elif server_handled_successfully(resp.status_int):
elif not is_server_error(resp.status_int):
# No sense retrying when we expect the same result
break
elif resp.status_int == HTTP_CONFLICT and 'x-timestamp' in [
header.lower() for header in headers]:
# Since the caller provided the timestamp, retrying won't
# change the result
break
# sleep only between tries, not after each one
if attempt < self.request_tries - 1:
if resp:

View File

@ -464,7 +464,7 @@ class TestInternalClient(unittest.TestCase):
# Since we didn't provide an X-Timestamp, retrying gives us a chance to
# succeed (assuming the failure was due to clock skew between servers)
expected = (' HTTP/1.0 409 ', ' HTTP/1.0 409 ', ' HTTP/1.0 409 ', )
expected = (' HTTP/1.0 409 ',)
loglines = client.logger.get_lines_for_level('info')
for expected, logline in izip_longest(expected, loglines):
if not expected: