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 7
7
from pathlib import Path , PurePosixPath , PureWindowsPath
8
8
import subprocess
9
9
import sys
10
+ import time
11
+ import typing
12
+ import urllib .error
10
13
import urllib .request
11
14
import typing
12
15
@@ -163,6 +166,21 @@ def get_externals() -> list[str]:
163
166
return externals
164
167
165
168
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
+
166
184
def check_sbom_packages (sbom_data : dict [str , typing .Any ]) -> None :
167
185
"""Make a bunch of assertions about the SBOM package data to ensure it's consistent."""
168
186
@@ -177,7 +195,7 @@ def check_sbom_packages(sbom_data: dict[str, typing.Any]) -> None:
177
195
# and that the download URL is valid.
178
196
if "checksums" not in package or "CI" in os .environ :
179
197
download_location = package ["downloadLocation" ]
180
- resp = urllib . request . urlopen (download_location )
198
+ resp = download_with_retries (download_location )
181
199
error_if (resp .status != 200 , f"Couldn't access URL: { download_location } '" )
182
200
183
201
package ["checksums" ] = [{
You can’t perform that action at this time.
0 commit comments