Skip to content

Commit dd9044c

Browse files
authored
More robust preupload retry mechanism (#6479)
* More robust preupload retry mechanism * Small fix
1 parent d78f070 commit dd9044c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/datasets/utils/hub.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from huggingface_hub import HfApi, hf_hub_url
55
from packaging import version
6-
from requests import HTTPError
6+
from requests import ConnectionError, HTTPError
77

88
from .. import config
99
from . import logging
@@ -18,15 +18,17 @@ def preupload_lfs_files(hf_api: HfApi, **kwargs):
1818
max_retries = 5
1919
base_wait_time = 1
2020
max_wait_time = 8
21-
status_codes = [500, 503]
2221
retry = 0
2322
while True:
2423
try:
2524
hf_api.preupload_lfs_files(**kwargs)
26-
except (RuntimeError, HTTPError) as err:
27-
if isinstance(err, RuntimeError) and isinstance(err.__cause__, HTTPError):
28-
err = err.__cause__
29-
if retry >= max_retries or err.response.status_code not in status_codes:
25+
except (RuntimeError, HTTPError, ConnectionError) as err:
26+
if isinstance(err, RuntimeError):
27+
if isinstance(err.__cause__, (HTTPError, ConnectionError)):
28+
err = err.__cause__
29+
else:
30+
raise err
31+
if retry >= max_retries or err.response and err.response.status_code not in [500, 503]:
3032
raise err
3133
else:
3234
sleep_time = min(max_wait_time, base_wait_time * 2**retry) # Exponential backoff

0 commit comments

Comments
 (0)