From 07fafb89a8415b052d4e2a2b77a89d2a35857cb9 Mon Sep 17 00:00:00 2001 From: Emma Harper Smith Date: Thu, 22 May 2025 19:16:02 -0700 Subject: [PATCH] Retry retries more - Increase max retry count to 7 - Increase base of exponential backoff to 2.25 - Add jitter in case there is some issue with sending requests at the same time - Also print the location that fails --- Tools/build/generate_sbom.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Tools/build/generate_sbom.py b/Tools/build/generate_sbom.py index 5845f2d85c7fdb..ecb7b54f6d8a13 100644 --- a/Tools/build/generate_sbom.py +++ b/Tools/build/generate_sbom.py @@ -4,6 +4,7 @@ import hashlib import json import os +import random import re import subprocess import sys @@ -164,16 +165,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