From 57dac29a5d0c472dd78d8b81514f10f7f3d6f7c7 Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Tue, 22 Nov 2022 13:49:44 +0100 Subject: [PATCH] fix: consistently retry on error codes in publish and install --- src/poetry/publishing/uploader.py | 3 ++- src/poetry/utils/authenticator.py | 3 ++- src/poetry/utils/constants.py | 3 +++ tests/utils/test_authenticator.py | 3 ++- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/poetry/publishing/uploader.py b/src/poetry/publishing/uploader.py index 1f3a6bd81b9..7e6cd6d9b6a 100644 --- a/src/poetry/publishing/uploader.py +++ b/src/poetry/publishing/uploader.py @@ -21,6 +21,7 @@ from poetry.__version__ import __version__ from poetry.utils.constants import REQUESTS_TIMEOUT +from poetry.utils.constants import STATUS_FORCELIST from poetry.utils.patterns import wheel_file_re @@ -68,7 +69,7 @@ def adapter(self) -> adapters.HTTPAdapter: connect=5, total=10, allowed_methods=["GET"], - status_forcelist=[500, 501, 502, 503], + status_forcelist=STATUS_FORCELIST, ) return adapters.HTTPAdapter(max_retries=retry) diff --git a/src/poetry/utils/authenticator.py b/src/poetry/utils/authenticator.py index 8db92913043..2b1011e4d56 100644 --- a/src/poetry/utils/authenticator.py +++ b/src/poetry/utils/authenticator.py @@ -24,6 +24,7 @@ from poetry.config.config import Config from poetry.exceptions import PoetryException from poetry.utils.constants import REQUESTS_TIMEOUT +from poetry.utils.constants import STATUS_FORCELIST from poetry.utils.password_manager import HTTPAuthCredential from poetry.utils.password_manager import PasswordManager @@ -259,7 +260,7 @@ def request( if is_last_attempt: raise e else: - if resp.status_code not in [502, 503, 504] or is_last_attempt: + if resp.status_code not in STATUS_FORCELIST or is_last_attempt: if raise_for_status: resp.raise_for_status() return resp diff --git a/src/poetry/utils/constants.py b/src/poetry/utils/constants.py index 0f799b16d7d..b755fb68e5e 100644 --- a/src/poetry/utils/constants.py +++ b/src/poetry/utils/constants.py @@ -3,3 +3,6 @@ # Timeout for HTTP requests using the requests library. REQUESTS_TIMEOUT = 15 + +# Server response codes to retry requests on. +STATUS_FORCELIST = [500, 501, 502, 503, 504] diff --git a/tests/utils/test_authenticator.py b/tests/utils/test_authenticator.py index 91e6a574bc8..545b73f53bf 100644 --- a/tests/utils/test_authenticator.py +++ b/tests/utils/test_authenticator.py @@ -249,7 +249,8 @@ def callback(*_: Any, **___: Any) -> None: (401, 0), (403, 0), (404, 0), - (500, 0), + (500, 5), + (501, 5), (502, 5), (503, 5), (504, 5),