Skip to content

Commit 3162ceb

Browse files
committed
pythonbuild: retry failed downloads
The network in GitHub Actions is horribly unreliable. Why, I'm not sure. Let's add automatic retry logic to downloads to hopefully reduce the base rate of errors.
1 parent 876fd64 commit 3162ceb

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

pythonbuild/utils.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import gzip
66
import hashlib
7+
import http.client
78
import io
89
import multiprocessing
910
import os
@@ -243,13 +244,19 @@ def download_to_path(url: str, path: pathlib.Path, size: int, sha256: str):
243244

244245
tmp = path.with_name("%s.tmp" % path.name)
245246

246-
try:
247-
with tmp.open("wb") as fh:
248-
for chunk in secure_download_stream(url, size, sha256):
249-
fh.write(chunk)
250-
except IntegrityError:
251-
tmp.unlink()
252-
raise
247+
for _ in range(5):
248+
try:
249+
try:
250+
with tmp.open("wb") as fh:
251+
for chunk in secure_download_stream(url, size, sha256):
252+
fh.write(chunk)
253+
254+
break
255+
except IntegrityError:
256+
tmp.unlink()
257+
raise
258+
except http.client.HTTPException as e:
259+
print("HTTP exception; retrying: %s" % e)
253260

254261
tmp.rename(path)
255262
print("successfully downloaded %s" % url)

0 commit comments

Comments
 (0)