Repository downloads don't retry an unknown host, despite --experimental_repository_downloader_retries
Description of the bug
#28023 (shipped in 9.0.0 as #28198) made UnknownHostException retryable in DownloadManager, so a short DNS outage should be retried. For http_file / http_archive downloads it doesn't seem to be: a fetch whose host doesn't resolve makes one attempt and fails, the same with --experimental_repository_downloader_retries=5 as with =0.
I think it's the exception nesting. HttpConnector throws an UnrecoverableHttpException with the UnknownHostException added as suppressed. HttpDownloader.download then collects the per-URL failures into a new IOException (aggregatedDownloadException) and adds each one as suppressed. shouldRetryDownload checks the exception and its direct suppressed list, so it sees the UnrecoverableHttpException but never the UnknownHostException inside it.
We ran into this in CI: a runner briefly couldn't resolve registry.npmjs.org, every npm tarball fetch failed on the first try, and we ended up wrapping the build in our own retry.
Related: even once the retry does fire, that loop has no delay between attempts, so a lookup failure lasting a couple of seconds could still use up every attempt. A short backoff there would make the retry useful for exactly the case #28023 was aimed at.
Which category does this issue belong to?
External Dependency
What's the simplest, easiest way to reproduce this bug?
.bazelversion:
9.3.1
MODULE.bazel:
http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
http_file(
name = "unresolvable",
url = "https://does-not-exist.invalid/file.tgz",
sha256 = "0000000000000000000000000000000000000000000000000000000000000000",
)
An empty BUILD.bazel, then:
bazel --batch build --experimental_repository_downloader_retries=5 \
--experimental_ui_debug_all_events @unresolvable//file
HttpConnector posts an Unknown host progress event on every attempt, so with 5 retries I'd expect 6 of them. I get one, plus a single Download from ... failed warning, which is exactly the output with --experimental_repository_downloader_retries=0:
PROGRESS <no location>: Unknown host: does-not-exist.invalid
WARNING <no location>: Download from https://does-not-exist.invalid/file.tgz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException Unknown host: does-not-exist.invalid
(.invalid never resolves, so this is a permanent failure, but it goes through the same code path as a transient one and makes the attempt count easy to see.)
Which operating system are you running Bazel on?
macOS 27 arm64 for the repro above; we saw it in CI on Linux x86_64.
What is the output of bazel info release?
release 9.3.1
Have you found anything relevant by searching the web?
#28023 / #28198, which added UnknownHostException to isRetryableException. I didn't find anything about it not taking effect. The code involved looks the same on master.
Any other information, logs, or outputs that you want to share?
A possible fix is to have shouldRetryDownload walk the suppressed exceptions recursively (or check causes too), rather than one level deep.
Do you want to send a PR? That analysis of the cause seems correct and a delay would also help.