From cbcbc774681ad1a90f8fd260787c29943bedb675 Mon Sep 17 00:00:00 2001 From: Clay Gerrard Date: Thu, 18 Jan 2018 18:33:08 -0800 Subject: [PATCH] Internal Client should only retry server errors Change-Id: I0a3f4a01d50b6a5d5528f527faa34573c7dde619 --- swift/common/internal_client.py | 14 ++++---------- test/unit/common/test_internal_client.py | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/swift/common/internal_client.py b/swift/common/internal_client.py index a5a9ad3407..4877724c4e 100644 --- a/swift/common/internal_client.py +++ b/swift/common/internal_client.py @@ -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: diff --git a/test/unit/common/test_internal_client.py b/test/unit/common/test_internal_client.py index fae36267be..a1ee399740 100644 --- a/test/unit/common/test_internal_client.py +++ b/test/unit/common/test_internal_client.py @@ -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: