From 6411fd38462a9e6ea9f5e0b44d9afe6fa54c0791 Mon Sep 17 00:00:00 2001 From: Mike Widman <mwidman@endurancewindpower.com> Date: Wed, 10 Jul 2013 10:52:02 -0700 Subject: [PATCH] Adds max-backoff for retries in Connection. The max-backoff concept prevents the backoff used in _retry to double infinitely (which in turn causes wait times of an hour or more between retries). As per review, changed code to use min instead. Fixes: bug #1183542 Change-Id: Ic084f54069b7fa7a33604741487045c5e697ff06 --- swiftclient/client.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/swiftclient/client.py b/swiftclient/client.py index 03dad314..0a320338 100644 --- a/swiftclient/client.py +++ b/swiftclient/client.py @@ -1044,9 +1044,9 @@ class Connection(object): def __init__(self, authurl=None, user=None, key=None, retries=5, preauthurl=None, preauthtoken=None, snet=False, - starting_backoff=1, tenant_name=None, os_options=None, - auth_version="1", cacert=None, insecure=False, - ssl_compression=True): + starting_backoff=1, max_backoff=64, tenant_name=None, + os_options=None, auth_version="1", cacert=None, + insecure=False, ssl_compression=True): """ :param authurl: authentication URL :param user: user name to authenticate as @@ -1081,6 +1081,7 @@ class Connection(object): self.attempts = 0 self.snet = snet self.starting_backoff = starting_backoff + self.max_backoff = max_backoff self.auth_version = auth_version self.os_options = os_options or {} if tenant_name: @@ -1152,7 +1153,7 @@ class Connection(object): else: raise sleep(backoff) - backoff *= 2 + backoff = min(backoff * 2, self.max_backoff) if reset_func: reset_func(func, *args, **kwargs)