bazelbuild / bazelbuild/bazel

"No such file or directory" when upgrading from v6.5.0 to 7.x.x

Open
#23,743 10 comments 0 reactions 0 assignees View on GitHub
team-Core type: bug untriaged
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the bug:

I'm trying to update a fairly complicated Bazel project from Bazel v6.5.0 to v7.x.x, but encountering strange issues. Unfortunately, I can't pinpoint _exactly_ where the issue lies, but I believe it is in Bazel itself, rather than any of the rules being imported.

**Expected behaviour**: upgrading from v6.5.0 to v7.x.x "just works"
**Actual behaviour**: the build fails due to files inside the `linux-sandbox` not being found

**More details**
Currently, on Bazel v6.5.0, the build reliably passes both on local development workstations and in the CI environment. Upgrading to v7.x.x causes the build to occasionally fail on development machines and much more consistently fail in CI. Unfortunately, I've been unable to reproduce in an isolated example project, and I'm not sure exactly how to go about collecting more information on the problem.

I've tried upgrading to v7.0.0, v7.1.2, v7.2.1 and v7.3.1 but they all behave the same way.

It's not always the same target that fails, but it's always roughly for the same reason, which is that a file is not found within the sandbox.

One example of this is shown below. A `bazel clean --expunge` was run first, and then (an equivalent of) `bazel test //... --test_tag_filters=smoke`, which first failed when trying to create an `ijar` for a `java_import` for a file checked into version control:

```
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
src/main/tools/linux-sandbox-pid1.cc:530: "execvp(external/rules_java~~toolchains~remote_java_tools_linux/java_tools/ijar/ijar, 0x1d1014a0)": No such file or directory
ERROR: lib/BUILD:2782:13: Extracting interface for jar lib/3rd-party/io.netty/netty-codec-haproxy/netty-codec-haproxy-4.1.113.Final.jar failed: (Exit 1): ijar failed: error executing JavaIjar command (from target //lib:netty-codec-haproxy)
(cd /home/warrens/.cache/bazel/_bazel_warrens/cf05af78ffeddb63393e16c80fd92083/sandbox/linux-sandbox/2/execroot/_main && \
exec env - \
PATH=/bin:/usr/bin:/usr/local/bin \
external/rules_java~~toolchains~remote_java_tools_linux/java_tools/ijar/ijar lib/3rd-party/io.netty/netty-codec-haproxy/netty-codec-haproxy-4.1.113.Final.jar bazel-out/k8-fastbuild/bin/lib/_ijar/netty-codec-haproxy/lib/3rd-party/io.netty/netty-codec-haproxy/netty-codec-haproxy-4.1.113.Final-ijar.jar --target_label //lib:netty-codec-haproxy)
```

Running the same `bazel test` command a second time also resulted in a failure, this time failing to run `java`:
```
ERROR: [snip]/BUILD:31:14: Building [snip]/SomeJavaTest.jar () failed: IOException while preparing the execution environment of a worker:
...
---8<---8<--- Exception details ---8<---8<---
java.io.IOException: Cannot run program "/home/warrens/.cache/bazel/_bazel_warrens/cf05af78ffeddb63393e16c80fd92083/execroot/_main/external/_main~java_repositories~jdk11/bin/java" (in directory "/home/warrens/.cache/bazel/_bazel_warrens/cf05af78ffeddb63393e16c80fd92083/execroot/_main"): error=2, No such file or directory
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1170)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1089)
at com.google.devtools.build.lib.shell.JavaSubprocessFactory.start(JavaSubprocessFactory.java:152)
...
Caused by: java.io.IOException: error=2, No such file or directory
at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
at java.base/java.lang.ProcessImpl.(ProcessImpl.java:295)
at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:225)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1126)
```

A third run of `bazel test` completed successfully.

A separate example, taken from the CI exhibits a similar mode of failure; this time during running of some tests:

```
ERROR: [snip]/BUILD:11:10: Testing //...:some-custom-test-rule failed: (Exit 1): generate-xml.sh failed: error executing TestRunner command (from target //...:some-custom-test-rule)
(cd /var/lib/jenkins/.cache/bazel/_bazel_jenkins/38b07d741dde33298ed2fff99f485394/sandbox/linux-sandbox/34/execroot/_main && \
exec env - \
EXPERIMENTAL_SPLIT_XML_GENERATION=1 \
JAVA_RUNFILES=bazel-out/k8-fastbuild/bin/.../some-custom-test-rule.runfiles \
PATH=/bin:/usr/bin:/usr/local/bin \
PYTHON_RUNFILES=bazel-out/k8-fastbuild/bin/.../some-custom-test-rule.runfiles \
RUNFILES_DIR=bazel-out/k8-fastbuild/bin/.../some-custom-test-rule.runfiles \
RUN_UNDER_RUNFILES=1 \
TEST_BINARY=.../some-custom-test-rule \
TEST_INFRASTRUCTURE_FAILURE_FILE=bazel-out/k8-fastbuild/testlogs/.../some-custom-test-rule/test.infrastructure_failure \
TEST_LOGSPLITTER_OUTPUT_FILE=bazel-out/k8-fastbuild/testlogs/.../some-custom-test-rule/test.raw_splitlogs/test.splitlogs \
TEST_NAME=//...:some-custom-test-rule \
TEST_PREMATURE_EXIT_FILE=bazel-out/k8-fastbuild/testlogs/.../some-custom-test-rule/test.exited_prematurely \
TEST_SHARD_INDEX=0 \
TEST_SIZE=small \
TEST_SRCDIR=bazel-out/k8-fastbuild/bin/.../some-custom-test-rule.runfiles \
TEST_TARGET=//...:some-custom-test-rule \
TEST_TIMEOUT=60 \
TEST_TMPDIR=_tmp/ff60cd74048852c7bacd3c1d1b00a8f2 \
TEST_TOTAL_SHARDS=0 \
TEST_UNDECLARED_OUTPUTS_ANNOTATIONS=bazel-out/k8-fastbuild/testlogs/.../some-custom-test-rule/test.outputs_manifest/ANNOTATIONS \
TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR=bazel-out/k8-fastbuild/testlogs/.../some-custom-test-rule/test.outputs_manifest \
TEST_UNDECLARED_OUTPUTS_DIR=bazel-out/k8-fastbuild/testlogs/.../some-custom-test-rule/test.outputs \
TEST_UNDECLARED_OUTPUTS_MANIFEST=bazel-out/k8-fastbuild/testlogs/.../some-custom-test-rule/test.outputs_manifest/MANIFEST \
TEST_UNDECLARED_OUTPUTS_ZIP=bazel-out/k8-fastbuild/testlogs/.../some-custom-test-rule/test.outputs/outputs.zip \
TEST_UNUSED_RUNFILES_LOG_FILE=bazel-out/k8-fastbuild/testlogs/.../some-custom-test-rule/test.unused_runfiles_log \
TEST_WARNINGS_OUTPUT_FILE=bazel-out/k8-fastbuild/testlogs/.../some-custom-test-rule/test.warnings \
TEST_WORKSPACE=_main \
TZ=UTC \
XML_OUTPUT_FILE=bazel-out/k8-fastbuild/testlogs/.../some-custom-test-rule/test.xml \
external/bazel_tools/tools/test/generate-xml.sh bazel-out/k8-fastbuild/testlogs/.../some-custom-test-rule/test.log bazel-out/k8-fastbuild/testlogs/.../some-custom-test-rule/test.xml 0 1)
# Configuration: 96d1f52e073df1fb1edb92e576742c56c7c33cdfdf7dc366cbda968896be461f
# Execution platform: @@platforms//host:host
```

At first glance, this looked to be a different type of failure; however, `cat`ing the `test.log` shows:

```
$ cat bazel-out/k8-fastbuild/testlogs/.../some-custom-test-rule/test.log
src/main/tools/linux-sandbox-pid1.cc:530: "execvp(external/bazel_tools/tools/test/test-setup.sh, 0xbd0c10)": No such file or directory
```

Some observations:

- In all cases, re-running the build seems to result in different behaviour; it will either succeed or fail at a different point
- The examples above are fairly Java-centric, because that is the vast majority of the project; however, I've seen other external tools (e.g. `node`) also fail.
- We have not _explicitly_ changed the value of `--incompatible_sandbox_hermetic_tmp` in these builds (so I believe it is set to the default value of `true`?); however, from what I can tell, adding `common --noincompatible_sandbox_hermetic_tmp` to `.bazelrc` does not help (I've tried explicitly setting both values, and the problem occurs with both)
- turning on `--sandbox_debug` gives a lot more output, but I couldn't see anything useful in there

Currently, I'm leaning towards this being a problem with multiple processes trying to interact with the sandbox at the same time; this would explain why I'm unable to reproduce it on a small project and why it fails more consistently in CI (bigger box with more cores to run tasks in parallel). However if I add `--jobs=1` the problem persists, which suggests this hypothesis is wrong.

Any suggestions on what could be tried in order to further triage or resolve this issue would be appreciated.

### Which category does this issue belong to?

Core

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

As mentioned, I can reproduce it fairly reliably on a large project; unfortunately, I'm yet to find a way of reproducing it on a example project. I'll keep trying though!

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

Linux (Fedora & CentOS)

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

7.3.1

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

n/a

### What's the output of `git remote get-url origin; git rev-parse HEAD` ?

```text
n/a
```

### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

I'm unable to run `bazelisk --bisect=6.5.0..7.0.0` because it attempts to revert back to v6.0.0, which is incompatible with most of the rules in `MODULE.bazel` :(

I'm trying to work out if I can use some of the 7.0.0 pre-release candidates to narrow down when it started failing, but so far no luck.

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

I found a similar sounding issue here: https://github.com/bazelbuild/bazel/issues/22151; however, this affects v6.5.0 and that is the version that is working for me.

Similarly, some comments in https://github.com/bazelbuild/bazel/pull/19943 seemed relevant, but I couldn't really turn them into useful avenues of investigation.

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

Output of `bazel mod graph`

```
(monorepo@_)
├───aspect_bazel_lib@1.42.1
│ ├───bazel_skylib@1.6.1 (*)
│ ├───platforms@0.0.10 (*)
│ └───stardoc@0.5.4
│ ├───bazel_skylib@1.6.1 (*)
│ ├───rules_java@7.3.1 (*)
│ └───rules_license@1.0.0 (*)
├───bazel_skylib@1.6.1
│ └───platforms@0.0.10 (*)
├───platforms@0.0.10
│ └───rules_license@1.0.0 (*)
├───rules_cc@0.0.9
│ └───platforms@0.0.10 (*)
├───rules_java@7.3.1
│ ├───bazel_skylib@1.6.1 (*)
│ ├───platforms@0.0.10 (*)
│ ├───rules_cc@0.0.9 (*)
│ ├───rules_license@1.0.0 (*)
│ └───rules_proto@6.0.0
│ ├───bazel_features@1.11.0 (*)
│ ├───bazel_skylib@1.6.1 (*)
│ └───rules_license@1.0.0 (*)
├───rules_jvm_external@5.3
│ ├───bazel_skylib@1.6.1 (*)
│ └───stardoc@0.5.4 (*)
├───rules_license@1.0.0
├───rules_oci@1.7.6
│ ├───aspect_bazel_lib@1.42.1 (*)
│ ├───bazel_skylib@1.6.1 (*)
│ ├───platforms@0.0.10 (*)
│ └───container_structure_test@1.16.0
│ ├───aspect_bazel_lib@1.42.1 (*)
│ ├───bazel_skylib@1.6.1 (*)
│ └───platforms@0.0.10 (*)
├───rules_pkg@0.9.1
│ ├───bazel_skylib@1.6.1 (*)
│ ├───rules_license@1.0.0 (*)
│ └───rules_python@0.34.0 (*)
└───rules_python@0.34.0
├───bazel_skylib@1.6.1 (*)
├───platforms@0.0.10 (*)
├───rules_cc@0.0.9 (*)
├───rules_proto@6.0.0 (*)
├───bazel_features@1.11.0
│ └───bazel_skylib@1.6.1 (*)
└───protobuf@24.4
├───bazel_skylib@1.6.1 (*)
├───platforms@0.0.10 (*)
├───rules_cc@0.0.9 (*)
├───rules_java@7.3.1 (*)
├───rules_jvm_external@5.3 (*)
├───rules_pkg@0.9.1 (*)
├───rules_proto@6.0.0 (*)
├───abseil-cpp@20230802.0.bcr.1
│ ├───bazel_skylib@1.6.1 (*)
│ ├───googletest@1.14.0 (*)
│ ├───platforms@0.0.10 (*)
│ └───rules_cc@0.0.9 (*)
├───googletest@1.14.0
│ ├───abseil-cpp@20230802.0.bcr.1 (*)
│ ├───platforms@0.0.10 (*)
│ └───rules_cc@0.0.9 (*)
├───upb@0.0.0-20230516-61a97ef
│ ├───abseil-cpp@20230802.0.bcr.1 (*)
│ ├───bazel_skylib@1.6.1 (*)
│ ├───platforms@0.0.10 (*)
│ ├───rules_pkg@0.9.1 (*)
│ └───rules_proto@6.0.0 (*)
└───zlib@1.3.1.bcr.3
├───platforms@0.0.10 (*)
└───rules_cc@0.0.9 (*)
```


I've tried upgrading various rules, but with no luck (and generally bringing in other difficulties!).

Contributor guide

Open the contributing guide

Research direction

Start with src/main/tools/linux-sandbox-pid1.cc and reproduce using bazel clean --expunge followed by bazel test //... --test_tag_filters=smoke on Bazel 6.5.0 and 7.x.x. Use --sandbox_debug and compare failures involving ijar, java, node, or test-setup.sh; done means obtaining a minimal reproduction and identifying the Bazel 7 regression or its cause.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, linux, node.js, python
Domain
build-system, operating-systems, testing
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.