[3.13] gh-134262: Add retries to generate_sbom.py (GH-134263) (#137468)
Some checks are pending
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if the ABI has changed (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run

(cherry picked from commit 0c5a8b0b55)

Co-authored-by: Semyon Moroz <donbarbos@proton.me>
This commit is contained in:
Emma Smith 2025-08-06 15:58:08 -07:00 committed by GitHub
parent b772427902
commit 7762de2527
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,6 +7,9 @@ import glob
from pathlib import Path, PurePosixPath, PureWindowsPath
import subprocess
import sys
import time
import typing
import urllib.error
import urllib.request
import typing
@ -163,6 +166,21 @@ def get_externals() -> list[str]:
return externals
def download_with_retries(download_location: str,
max_retries: int = 5,
base_delay: float = 2.0) -> typing.Any:
"""Download a file with exponential backoff retry."""
for attempt in range(max_retries):
try:
resp = urllib.request.urlopen(download_location)
except urllib.error.URLError as ex:
if attempt == max_retries:
raise ex
time.sleep(base_delay**attempt)
else:
return resp
def check_sbom_packages(sbom_data: dict[str, typing.Any]) -> None:
"""Make a bunch of assertions about the SBOM package data to ensure it's consistent."""
@ -177,7 +195,7 @@ def check_sbom_packages(sbom_data: dict[str, typing.Any]) -> None:
# and that the download URL is valid.
if "checksums" not in package or "CI" in os.environ:
download_location = package["downloadLocation"]
resp = urllib.request.urlopen(download_location)
resp = download_with_retries(download_location)
error_if(resp.status != 200, f"Couldn't access URL: {download_location}'")
package["checksums"] = [{