Skip to content

Commit

Permalink
fix: consistently retry on error codes in publish and install
Browse files Browse the repository at this point in the history
  • Loading branch information
nejch committed Mar 28, 2023
1 parent 2b15ce1 commit a5ecc08
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/poetry/publishing/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/poetry/utils/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/poetry/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
3 changes: 2 additions & 1 deletion tests/utils/test_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit a5ecc08

Please sign in to comment.