From 3ce7fae3fd41dee182f6a67a6c3501491b47ef87 Mon Sep 17 00:00:00 2001 From: Lucain Pouget Date: Mon, 26 Jun 2023 11:44:03 +0200 Subject: [PATCH 1/2] Retry on both ConnectTimeout and ReadTimeout --- src/huggingface_hub/file_download.py | 6 +++--- src/huggingface_hub/utils/_http.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/huggingface_hub/file_download.py b/src/huggingface_hub/file_download.py index bf4d4aab56..59344516fd 100644 --- a/src/huggingface_hub/file_download.py +++ b/src/huggingface_hub/file_download.py @@ -19,7 +19,7 @@ import requests from filelock import FileLock -from requests.exceptions import ConnectTimeout, ProxyError +from requests.exceptions import Timeout, ProxyError from huggingface_hub import constants @@ -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`): @@ -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, diff --git a/src/huggingface_hub/utils/_http.py b/src/huggingface_hub/utils/_http.py index cec904f8de..88dd52f089 100644 --- a/src/huggingface_hub/utils/_http.py +++ b/src/huggingface_hub/utils/_http.py @@ -22,7 +22,7 @@ import requests from requests import Response -from requests.exceptions import ConnectTimeout, ProxyError +from requests.exceptions import Timeout, ProxyError from . import logging from ._typing import HTTP_METHOD_T @@ -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, @@ -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. From 2b7ce0f24cc255ef28c9f15fcad3cb8c8b5587af Mon Sep 17 00:00:00 2001 From: Lucain Pouget Date: Mon, 26 Jun 2023 11:51:36 +0200 Subject: [PATCH 2/2] make style --- src/huggingface_hub/file_download.py | 2 +- src/huggingface_hub/utils/_http.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/huggingface_hub/file_download.py b/src/huggingface_hub/file_download.py index 59344516fd..d4857532ea 100644 --- a/src/huggingface_hub/file_download.py +++ b/src/huggingface_hub/file_download.py @@ -19,7 +19,7 @@ import requests from filelock import FileLock -from requests.exceptions import Timeout, ProxyError +from requests.exceptions import ProxyError, Timeout from huggingface_hub import constants diff --git a/src/huggingface_hub/utils/_http.py b/src/huggingface_hub/utils/_http.py index 88dd52f089..0448d4f0cd 100644 --- a/src/huggingface_hub/utils/_http.py +++ b/src/huggingface_hub/utils/_http.py @@ -22,7 +22,7 @@ import requests from requests import Response -from requests.exceptions import Timeout, ProxyError +from requests.exceptions import ProxyError, Timeout from . import logging from ._typing import HTTP_METHOD_T