Skip to content

Commit c0acc68

Browse files
author
Greg Lindahl
committed
retry backoff
1 parent 56c3031 commit c0acc68

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

cdx_toolkit/myrequests.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def myrequests_get(url, params=None, headers=None, cdx=False, allow404=False):
3838
headers['User-Agent'] = 'pypi_cdx_toolkit/'+__version__
3939

4040
retry = True
41+
retry_sec = 1
42+
retry_max_sec = 30
4143
retries = 0
4244
connect_errors = 0
4345
while retry:
@@ -58,6 +60,7 @@ def myrequests_get(url, params=None, headers=None, cdx=False, allow404=False):
5860
# 503=slow down, 50[24] are temporary outages, 500=Amazon S3 generic error
5961
# CC takes a 503 from storage and then emits a 500 with error text in resp.text
6062
# I have never seen IA or CC send 429 or 509, but just in case...
63+
# 429 is also a slow down, IA started sending them mid-2023
6164
retries += 1
6265
if retries > 5:
6366
LOGGER.warning('retrying after 1s for %d', resp.status_code)
@@ -67,7 +70,8 @@ def myrequests_get(url, params=None, headers=None, cdx=False, allow404=False):
6770
LOGGER.info('retrying after 1s for %d', resp.status_code)
6871
if resp.text:
6972
LOGGER.info('response body is %s', resp.text)
70-
time.sleep(1)
73+
time.sleep(retry_sec)
74+
retry_sec = min(retry_sec*2, retry_max_sec)
7175
continue
7276
if resp.status_code in {400, 404}: # pragma: no cover
7377
if resp.text:
@@ -90,7 +94,8 @@ def myrequests_get(url, params=None, headers=None, cdx=False, allow404=False):
9094
if connect_errors > 10:
9195
LOGGER.warning(string)
9296
LOGGER.info('retrying after 1s for '+str(e))
93-
time.sleep(1)
97+
time.sleep(retry_sec)
98+
retry_sec = min(retry_sec*2, retry_max_sec)
9499
except requests.exceptions.RequestException as e: # pragma: no cover
95100
LOGGER.warning('something unexpected happened, giving up after %s', str(e))
96101
raise

0 commit comments

Comments
 (0)