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 downloads when <75% of the file is downloaded #496

Merged
merged 1 commit into from
Jan 14, 2025
Merged
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
12 changes: 10 additions & 2 deletions pythonbuild/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ def write_target_settings(targets, dest_path: pathlib.Path):
class IntegrityError(Exception):
"""Represents an integrity error when downloading a URL."""

def __init__(self, *args, length: int):
self.length = length
super().__init__(*args)


def secure_download_stream(url, size, sha256):
"""Securely download a URL to a stream of chunks.
Expand Down Expand Up @@ -291,9 +295,13 @@ def download_to_path(url: str, path: pathlib.Path, size: int, sha256: str):
fh.write(chunk)

break
except IntegrityError:
except IntegrityError as e:
tmp.unlink()
raise
# If we didn't get most of the expected file, retry
if e.length > size * 0.75:
raise
print(f"Integrity error on {url}; retrying: {e}")
time.sleep(2**attempt)
except http.client.HTTPException as e:
print(f"HTTP exception on {url}; retrying: {e}")
time.sleep(2**attempt)
Expand Down
Loading