]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-134262: increase retries in `Tools/build/generate_sbom.py` … (#137496)
authorEmma Smith <emma@emmatyping.dev>
Thu, 7 Aug 2025 04:17:28 +0000 (21:17 -0700)
committerGitHub <noreply@github.com>
Thu, 7 Aug 2025 04:17:28 +0000 (07:17 +0300)
[3.13] gh-134262: increase retries in `Tools/build/generate_sbom.py` (GH-134558)
(cherry picked from commit 3f9eb55e090a8de80503e565f508f341c5f4c8da)

Tools/build/generate_sbom.py

index 450d163fd3b7a6c1ab152b58c4dcd0a2647af12b..82f06f0a7e57f9d6c65320563a8c3070c5910a98 100644 (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