Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry on both ConnectTimeout and ReadTimeout #1529

Merged
merged 2 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/huggingface_hub/file_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import requests
from filelock import FileLock
from requests.exceptions import ConnectTimeout, ProxyError
from requests.exceptions import ProxyError, Timeout

from huggingface_hub import constants

Expand Down Expand Up @@ -373,7 +373,7 @@ def _request_wrapper(
If enabled, a `OfflineModeIsEnabled` exception is raised.
2. Follow relative redirections if `follow_relative_redirects=True` even when
`allow_redirection` kwarg is set to False.
3. Retry in case request fails with a `ConnectTimeout`, with exponential backoff.
3. Retry in case request fails with a `Timeout` or `ProxyError`, with exponential backoff.

Args:
method (`str`):
Expand Down Expand Up @@ -445,7 +445,7 @@ def _request_wrapper(
max_retries=max_retries,
base_wait_time=base_wait_time,
max_wait_time=max_wait_time,
retry_on_exceptions=(ConnectTimeout, ProxyError),
retry_on_exceptions=(Timeout, ProxyError),
retry_on_status_codes=(),
timeout=timeout,
**params,
Expand Down
8 changes: 4 additions & 4 deletions src/huggingface_hub/utils/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import requests
from requests import Response
from requests.exceptions import ConnectTimeout, ProxyError
from requests.exceptions import ProxyError, Timeout

from . import logging
from ._typing import HTTP_METHOD_T
Expand Down Expand Up @@ -119,7 +119,7 @@ def http_backoff(
base_wait_time: float = 1,
max_wait_time: float = 8,
retry_on_exceptions: Union[Type[Exception], Tuple[Type[Exception], ...]] = (
ConnectTimeout,
Timeout,
ProxyError,
),
retry_on_status_codes: Union[int, Tuple[int, ...]] = HTTPStatus.SERVICE_UNAVAILABLE,
Expand Down Expand Up @@ -148,10 +148,10 @@ def http_backoff(
`max_wait_time`.
max_wait_time (`float`, *optional*, defaults to `8`):
Maximum duration (in seconds) to wait before retrying.
retry_on_exceptions (`Type[Exception]` or `Tuple[Type[Exception]]`, *optional*, defaults to `(ConnectTimeout, ProxyError,)`):
retry_on_exceptions (`Type[Exception]` or `Tuple[Type[Exception]]`, *optional*, defaults to `(Timeout, ProxyError,)`):
Define which exceptions must be caught to retry the request. Can be a single
type or a tuple of types.
By default, retry on `ConnectTimeout` and `ProxyError`.
By default, retry on `Timeout` and `ProxyError`.
retry_on_status_codes (`int` or `Tuple[int]`, *optional*, defaults to `503`):
Define on which status codes the request must be retried. By default, only
HTTP 503 Service Unavailable is retried.
Expand Down