Skip to content

Commit

Permalink
Retry on both ConnectTimeout and ReadTimeout (#1529)
Browse files Browse the repository at this point in the history
* Retry on both ConnectTimeout and ReadTimeout

* make style
  • Loading branch information
Wauplin authored Jun 26, 2023
1 parent 3832f67 commit fd1494a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
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

0 comments on commit fd1494a

Please sign in to comment.