Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Set download retries and log download exceptions for installer failures #7600

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

Merged
merged 3 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions localstack/packages/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def _install(self, target: InstallTarget) -> None:
archive_name = os.path.basename(download_url)
download_and_extract(
download_url,
retries=3,
tmp_archive=os.path.join(config.dirs.tmp, archive_name),
target_dir=target_directory,
)
Expand Down
18 changes: 16 additions & 2 deletions localstack/utils/archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,26 @@ def download_and_extract(archive_url, target_dir, retries=0, sleep=3, tmp_archiv
if not os.path.exists(tmp_archive) or os.path.getsize(tmp_archive) <= 0:
# create temporary placeholder file, to avoid duplicate parallel downloads
save_file(tmp_archive, "")

for i in range(retries + 1):
try:
download(archive_url, tmp_archive)
break
except Exception:
time.sleep(sleep)
except Exception as e:
LOG.warning(
"Attempt %d. Failed to download archive from %s: %s",
i + 1,
archive_url,
e,
)
# only sleep between retries, not after the last one
if i < retries:
time.sleep(sleep)

# if the temporary file we created above hasn't been replaced, we assume failure
if os.path.getsize(tmp_archive) <= 0:
raise Exception("Failed to download archive from %s: . Retries exhausted", archive_url)
Comment on lines +205 to +206
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: can this actually ever be a negative value? The docs state that in case of inaccessibility, OSError is returned.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, just copied this from L185.

Like you said, probably not, but I guess we still wouldn't want it if for some reason this would happen on some esoteric system 🤷‍♂️


if ext == ".zip":
unzip(tmp_archive, target_dir)
elif ext in (
Expand Down