File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 77from pathlib import Path , PurePosixPath , PureWindowsPath
88import subprocess
99import sys
10+ import time
11+ import typing
12+ import urllib .error
1013import urllib .request
1114import typing
1215
@@ -163,6 +166,21 @@ def get_externals() -> list[str]:
163166 return externals
164167
165168
169+ def download_with_retries (download_location : str ,
170+ max_retries : int = 5 ,
171+ base_delay : float = 2.0 ) -> typing .Any :
172+ """Download a file with exponential backoff retry."""
173+ for attempt in range (max_retries ):
174+ try :
175+ resp = urllib .request .urlopen (download_location )
176+ except urllib .error .URLError as ex :
177+ if attempt == max_retries :
178+ raise ex
179+ time .sleep (base_delay ** attempt )
180+ else :
181+ return resp
182+
183+
166184def check_sbom_packages (sbom_data : dict [str , typing .Any ]) -> None :
167185 """Make a bunch of assertions about the SBOM package data to ensure it's consistent."""
168186
@@ -177,7 +195,7 @@ def check_sbom_packages(sbom_data: dict[str, typing.Any]) -> None:
177195 # and that the download URL is valid.
178196 if "checksums" not in package or "CI" in os .environ :
179197 download_location = package ["downloadLocation" ]
180- resp = urllib . request . urlopen (download_location )
198+ resp = download_with_retries (download_location )
181199 error_if (resp .status != 200 , f"Couldn't access URL: { download_location } '" )
182200
183201 package ["checksums" ] = [{
You can’t perform that action at this time.
0 commit comments