[3.13] gh-134262: increase retries in Tools/build/generate_sbom.py … (#137496)

[3.13] gh-134262: increase retries in `Tools/build/generate_sbom.py` (GH-134558)
(cherry picked from commit 3f9eb55e09)
This commit is contained in:
Emma Smith 2025-08-06 21:17:28 -07:00 committed by GitHub
parent 7762de2527
commit 751a890f16
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,5 +1,6 @@
"""Tool for generating Software Bill of Materials (SBOM) for Python's dependencies"""
import os
import random
import re
import hashlib
import json
@ -167,16 +168,18 @@ def get_externals() -> list[str]:
def download_with_retries(download_location: str,
max_retries: int = 5,
base_delay: float = 2.0) -> typing.Any:
max_retries: int = 7,
base_delay: float = 2.25,
max_jitter: float = 1.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)
msg = f"Download from {download_location} failed."
raise OSError(msg) from ex
time.sleep(base_delay**attempt + random.uniform(0, max_jitter))
else:
return resp