Crash (IllegalArgumentException "cannot relativize") when a remote-execution input from --experimental_remote_repo_contents_cache is missing from the remote CAS
Description of the bug:
With --experimental_remote_repo_contents_cache, Bazel 9.3.0 crashes with an
internal error, not a lost-input recovery, when an action input that
comes from a repository served by the remote repo contents cache is reported
missing by FindMissingBlobs before remote execution.
FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node 'ActionLookupData0{actionLookupKey=ConfiguredTargetKey{label=//pkg:test, config=BuildConfigurationKey[...]}, actionIndex=0}' (requested by nodes ...)
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:552)
...
Caused by: java.lang.IllegalArgumentException: Path '<output_base>/external/+browser+website_chromium_darwin_arm64/LICENSE.headless_shell' is not under '<output_base>/execroot/_main', cannot relativize
at com.google.devtools.build.lib.vfs.PathFragment.relativeTo(PathFragment.java:378)
at com.google.devtools.build.lib.remote.common.RemotePathResolver$DefaultRemotePathResolver.localPathToExecPath(RemotePathResolver.java:112)
at com.google.devtools.build.lib.remote.RemoteExecutionCache.lambda$uploadFile$0(RemoteExecutionCache.java:224)
...
at com.google.devtools.build.lib.remote.RemoteExecutionCache.uploadFile(RemoteExecutionCache.java:214)
at com.google.devtools.build.lib.remote.merkletree.MerkleTree$Uploadable.upload(MerkleTree.java:193)
at com.google.devtools.build.lib.remote.RemoteExecutionCache.uploadBlob(RemoteExecutionCache.java:297)
at com.google.devtools.build.lib.remote.RemoteExecutionCache.lambda$maybeCreateUploadTask$5(RemoteExecutionCache.java:381)
...
at com.google.devtools.build.lib.remote.RemoteExecutionCache.lambda$findMissingBlobs$5(RemoteExecutionCache.java:442)
...
What happens, reading the 9.3.0 source:
- The repository
+browser+website_chromium_darwin_arm64(a plainhttp_archive) is served by the remote repo contents cache, so its files exist only in the remote external overlay file system; the on-disk<output_base>/external/<repo>/contains onlyREPO.bazel. - An action that takes one of the repo's files as input is executed remotely.
FindMissingBlobsreports that file's blob missing from the remote CAS. RemoteExecutionCache.uploadFilefinds the file is not available locally and takes the branch commented "the remote input was determined to exist ... but reported to be missing ... possibly because it was evicted in the interim". To build theCacheNotFoundExceptionit callsremotePathResolver.localPathToExecPath(path).DefaultRemotePathResolver.localPathToExecPathislocalPath.relativeTo(execRoot). The path is under<output_base>/external/..., not under<output_base>/execroot/_main, sorelativeTothrowsIllegalArgumentExceptionand the server crashes (exit code 37).
So the lost-input path that exists for exactly this situation cannot handle an
input whose local path is in the remote-repo overlay under
<output_base>/external. Even if the exception were built correctly, it is
not clear that action rewinding / lost-input handling can recover a lost input
belonging to a remote-cached repository (that would need the repository to be
re-fetched and re-uploaded), so the expected behavior may need more than the
path fix.
How the state arose in our case: the repo's cache entry was answered by the
local --disk_cache, not by the remote cache.
RemoteRepoContentsCacheImpl.buildContext reads with CachePolicy.ANY_CACHE,
and the disk cache held the repo's action-cache entry from an earlier fetch.
The remote CAS had since lost 3 of the repo's 23 blobs. A disk-cache hit does
not go through the remote server's completeness checking, so Bazel accepted a
repository the remote CAS no longer fully held, and the first remote action
that needed a lost file crashed the server. Asked directly (fresh output base,
--disk_cache=), the remote cache (Buildbarn) correctly rejected the entry:
GetActionResult NOT_FOUND: Object 1-09d2153b56e27616a5402096aaccaf0f363a42c6a3a6bf085f204956eaf2eb9b-1741976- referenced by the action result is not present in the Content Addressable Storage
That fetch then re-uploaded the missing blobs and the crash stopped. The failure was deterministic until then: it reproduced on two different client machines, including one starting from an empty output base, because each machine's disk cache held the same entry.
Expected behavior: a missing input from a remote-cached repository should not crash the server. Ideally Bazel re-fetches the repository (or treats the cached repository as invalid) and continues, or at minimum fails the build with a normal error. Separately, it may be worth considering whether a disk-cache hit for a remote repo contents cache entry should be trusted when the files will later be needed from the remote CAS.
Which category does this issue belong to?
Remote Execution
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
We have not reduced this to a minimal repository yet. The shape, from what we observed:
- Remote execution with a remote cache (we use Buildbarn), plus
--disk_cache=<dir>, and the startup option--experimental_remote_repo_contents_cachewith--repo_contents_cache=. - An
http_archiverepository whose files are inputs to a remotely executed action, e.g. afilegroup(srcs = glob(["**"]))used as test data. - Build once so the repository is uploaded to the remote repo contents cache and its action-cache entry is written through to the disk cache.
- Delete one of the repository's file blobs from the remote CAS (eviction, in our case).
- With a fresh output base and the same disk cache, build a target whose remotely executed action needs that file (and is not an action-cache hit). The server crashes with the trace above.
Relevant flags from the failing invocation:
startup: --experimental_remote_repo_contents_cache
--remote_cache=grpc://...
--remote_executor=grpc://...
--disk_cache=<dir>
--repo_contents_cache=
--remote_download_outputs=minimal
--remote_upload_local_results
Which operating system are you running Bazel on?
Linux x86_64 client (Ubuntu); the action executed remotely on a macOS arm64 worker.
What is the output of bazel info release?
release 9.3.0
If bazel info release returns development version or (@non-git), tell us how you built Bazel.
No response
What's the output of git remote get-url origin; git rev-parse HEAD ?
Private repository.
If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.
Not known to be a regression; we have only seen it on 9.3.0.
Have you found anything relevant by searching the web?
No existing issue found searching for "cannot relativize" together with
remote repo contents cache / localPathToExecPath.
Any other information, logs or outputs that you want to share?
Source references at the 9.3.0 tag:
src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionCache.java,uploadFile: the!isAvailableLocallybranch that callslocalPathToExecPath.src/main/java/com/google/devtools/build/lib/remote/common/RemotePathResolver.java,DefaultRemotePathResolver.localPathToExecPath:relativeTo(execRoot).src/main/java/com/google/devtools/build/lib/remote/RemoteRepoContentsCacheImpl.java,buildContext: lookups read withCachePolicy.ANY_CACHE.
@bazel-io fork 9.4.0
@bazel-io fork 10.0.0
This will be fixed by https://github.com/bazelbuild/bazel/issues/31258 as it's already fixed at HEAD and in 10.0.0rc1.