fix(cross): retry transient augment-source downloads

A cross build fetches each augment source (e.g. libdisplay-info) on every CI
job, so a single upstream hiccup — observed as a gitlab 500 on the
libdisplay-info tarball — failed the whole job. Retry the download up to 4 times
with linear backoff on transient responses (HTTP 5xx / 429) and network
(IOException) errors; 4xx and the like still fail fast.

Signed-off-by: Joel Winarske <joel.winarske@gmail.com>
This commit is contained in:
Joel Winarske
2026-06-20 07:53:16 -07:00
parent 10b9eaf902
commit df4c1759c2
+26 -7
View File
@@ -225,14 +225,33 @@ class OverlayBuilder {
}
Future<void> _download(String url, File dest) async {
final req = await _http.getUrl(Uri.parse(url));
req.followRedirects = true;
final resp = await req.close();
if (resp.statusCode != 200) {
await resp.drain<void>();
throw OverlayBuildException('download failed ($url): ${resp.statusCode}');
// Retry transient failures (5xx / 429 / network) with backoff — a CI run
// fetches augment sources on every job, so a single upstream hiccup (e.g.
// a gitlab 500) shouldn't fail the build. 4xx and the like fail fast.
const maxAttempts = 4;
for (var attempt = 1; ; attempt++) {
try {
final req = await _http.getUrl(Uri.parse(url));
req.followRedirects = true;
final resp = await req.close();
if (resp.statusCode == 200) {
await resp.pipe(dest.openWrite());
return;
}
await resp.drain<void>();
final transient = resp.statusCode >= 500 || resp.statusCode == 429;
if (!transient || attempt == maxAttempts) {
throw OverlayBuildException(
'download failed ($url): ${resp.statusCode}',
);
}
} on IOException catch (e) {
if (attempt == maxAttempts) {
throw OverlayBuildException('download failed ($url): $e');
}
}
await Future<void>.delayed(Duration(seconds: attempt * 2));
}
await resp.pipe(dest.openWrite());
}
/// Close the underlying HTTP client.