bazelbuild / bazelbuild/bazel

Bazel crash when repository cache path cannot be created

Open
#20,547 0 comments 0 reactions 0 assignees View on GitHub
help wanted P2 team-ExternalDeps type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the bug:

Due to a misconfiguration, my repo got into a state where this flag is set `--repository_cache=` in my bazelrc. Running Bazel with such a config caused this crash to happen.

```
FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node 'REPOSITORY_DIRECTORY:@@rules_pkg' (requested by nodes 'PACKAGE_LOOKUP:@@rules_pkg//')
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:550)
at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:414)
at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(Unknown Source)
at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
Caused by: net.starlark.java.eval.Starlark$UncheckedEvalException: UnsupportedOperationException thrown during Starlark evaluation (LOADING)
at .download_and_extract(:0)
at ._http_archive_impl(/private/var/tmp/_bazel_sluongng/0fd4abe8e9728bd678b1511337808ad4/external/bazel_tools/tools/build_defs/repo/http.bzl:145)
Caused by: java.lang.UnsupportedOperationException: /home/runner/repo-cache/content_addressable/sha256 (Operation not supported)
at com.google.devtools.build.lib.unix.NativePosixFiles.mkdirs(Native Method)
at com.google.devtools.build.lib.unix.UnixFileSystem.createDirectoryAndParents(UnixFileSystem.java:360)
at com.google.devtools.build.lib.vfs.Path.createDirectoryAndParents(Path.java:460)
at com.google.devtools.build.lib.bazel.repository.cache.RepositoryCache.ensureCacheDirectoryExists(RepositoryCache.java:273)
at com.google.devtools.build.lib.bazel.repository.cache.RepositoryCache.put(RepositoryCache.java:230)
at com.google.devtools.build.lib.bazel.repository.downloader.DownloadManager.download(DownloadManager.java:279)
at com.google.devtools.build.lib.bazel.repository.starlark.StarlarkBaseExternalContext.downloadAndExtract(StarlarkBaseExternalContext.java:685)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at net.starlark.java.eval.MethodDescriptor.call(MethodDescriptor.java:162)
at net.starlark.java.eval.BuiltinFunction.fastcall(BuiltinFunction.java:78)
at net.starlark.java.eval.Starlark.fastcall(Starlark.java:806)
at net.starlark.java.eval.Eval.evalCall(Eval.java:682)
at net.starlark.java.eval.Eval.eval(Eval.java:497)
at net.starlark.java.eval.Eval.execAssignment(Eval.java:109)
at net.starlark.java.eval.Eval.exec(Eval.java:268)
at net.starlark.java.eval.Eval.execStatements(Eval.java:82)
at net.starlark.java.eval.Eval.execFunctionBody(Eval.java:66)
at net.starlark.java.eval.StarlarkFunction.fastcall(StarlarkFunction.java:179)
at net.starlark.java.eval.Starlark.fastcall(Starlark.java:806)
at net.starlark.java.eval.Starlark.call(Starlark.java:772)
at com.google.devtools.build.lib.bazel.repository.starlark.StarlarkRepositoryFunction.fetchInternal(StarlarkRepositoryFunction.java:289)
at com.google.devtools.build.lib.bazel.repository.starlark.StarlarkRepositoryFunction.fetch(StarlarkRepositoryFunction.java:145)
at com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction.fetchRepository(RepositoryDelegatorFunction.java:294)
at com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction.compute(RepositoryDelegatorFunction.java:194)
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:461)
at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:414)
at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(Unknown Source)
at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
exit 37
```

### Which category does this issue belong to?

External Dependency

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Build on MacOS and set the repository cache to an uncreatable path

### Which operating system are you running Bazel on?

MacOS Sonoma 14.2

### What is the output of `bazel info release`?

release 6.4.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 master; git rev-parse HEAD` ?

```text
Irrelevant
```

### Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

Most likely not

### Have you found anything relevant by searching the web?

_No response_

### Any other information, logs, or outputs that you want to share?

This seems like an unhandled exception.

The code is expecting IOException but `java.lang.UnsupportedOperationException` is RuntimeException.

Contributor guide

Open the contributing guide

Research direction

Start at RepositoryCache.ensureCacheDirectoryExists and RepositoryCache.put, which appear in the stack trace, and reproduce with --repository_cache set to an uncreatable path on macOS. Trace the directory-creation exception handling and add coverage for this configuration. Done means Bazel reports the cache-path failure without crashing with an unhandled UnsupportedOperationException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.