Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paths to Param Files in Command Lines Refer to Host Execroot Paths (instead of sandbox execroot paths) With --incompatible_sandbox_hermetic_tmp=true #20515

Closed
rrbutani opened this issue Dec 12, 2023 · 12 comments
Assignees
Labels
team-Local-Exec Issues and PRs for the Execution (Local) team type: bug

Comments

@rrbutani
Copy link
Contributor

rrbutani commented Dec 12, 2023

Issue

Building Bazel at HEAD with Bazel 7.0.0 (with --incompatible_sandbox_hermetic_tmp=true, as is the default in Bazel 7) and an output base on /tmp yields the following error about a .params file not being found:

bazel-7.0.0-linux-x86_64 --output_user_root=/tmp/rrbutani-bazel build //src:bazel -c opt
ERROR: /src/dev/bazel/src/main/java/com/google/devtools/build/lib/analysis/BUILD:153:13: Compiling Java headers src/main/java/com/google/devtools/build/lib/analysis/libanalysis_cluster-hjar.jar (109 source files) failed: (Exit 1): linux-sandbox failed: error executing Turbine command
  (cd /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/execroot/_main && \
  exec env - \
    LC_CTYPE=en_US.UTF-8 \
    PATH=/usr/local/bin:/usr/bin:/bin \
    TMPDIR=/tmp \
  /tmp/bazel-rrbutani/install/89a68939cbf63eb54205fdf943a58b15/linux-sandbox -W /tmp/bazel-working-directory/_main -t 15 -w /tmp/bazel-execroot/_main -w /tmp -w /dev/shm -M /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/execroot -m /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-execroot -M /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/execroot -m /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-working-directory -M /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/external/rules_java~7.3.1~toolchains~remote_java_tools_linux -m /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-source-roots/0 -M /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/external/rules_java~7.3.1~toolchains~remotejdk21_linux -m /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-source-roots/1 -M /src/dev/bazel -m /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-source-roots/2 -M /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp -m /tmp -S /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/stats.out -D /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/debug.out -- external/rules_java~7.3.1~toolchains~remote_java_tools_linux/java_tools/turbine_direct_graal '-Dturbine.ctSymPath=external/rules_java~7.3.1~toolchains~remotejdk21_linux/lib/ct.sym' @bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libanalysis_cluster-hjar.jar-0.params)
java.lang.AssertionError: params file does not exist: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libanalysis_cluster-hjar.jar-0.params
        at com.google.turbine.options.TurbineOptionsParser.expandParamsFiles(TurbineOptionsParser.java:182)
        at com.google.turbine.options.TurbineOptionsParser.parse(TurbineOptionsParser.java:49)
        at com.google.turbine.options.TurbineOptionsParser.parse(TurbineOptionsParser.java:38)
        at com.google.turbine.main.Main.compile(Main.java:133)
        at com.google.turbine.main.Main.main(Main.java:89)
Target //src:bazel failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.225s, Critical Path: 0.15s
INFO: 3 processes: 3 internal.
ERROR: Build did NOT complete successfully

If --incompatible_sandbox_hermetic_tmp=false is passed, the above command succeeds.

Details

Running with --sandbox_debug produces the following:

Click to expand
DEBUG: Sandbox debug output for Turbine //src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster: 1702418703.999694695: src/main/tools/linux-sandbox.cc:156: calling pipe(2)...
1702418703.999718491: src/main/tools/linux-sandbox.cc:165: Netns is 0
1702418703.999720291: src/main/tools/linux-sandbox.cc:176: calling clone(2)...
1702418704.000568193: src/main/tools/linux-sandbox.cc:185: linux-sandbox-pid1 has PID 30502
1702418704.000590115: src/main/tools/linux-sandbox-pid1.cc:700: Pid1Main started
1702418704.000652861: src/main/tools/linux-sandbox.cc:202: done manipulating pipes
1702418704.000775265: src/main/tools/linux-sandbox-pid1.cc:302: bind mount: /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/execroot -> /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-execroot
1702418704.000791794: src/main/tools/linux-sandbox-pid1.cc:302: bind mount: /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/execroot -> /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-working-directory
1702418704.000799418: src/main/tools/linux-sandbox-pid1.cc:302: bind mount: /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/external/rules_java~7.3.1~toolchains~remote_java_tools_linux -> /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-source-roots/0
1702418704.000809258: src/main/tools/linux-sandbox-pid1.cc:302: bind mount: /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/external/rules_java~7.3.1~toolchains~remotejdk21_linux -> /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-source-roots/1
1702418704.000815958: src/main/tools/linux-sandbox-pid1.cc:302: bind mount: /src/dev/bazel -> /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-source-roots/2
1702418704.000834430: src/main/tools/linux-sandbox-pid1.cc:302: bind mount: /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp -> /tmp
1702418704.000848407: src/main/tools/linux-sandbox-pid1.cc:311: writable: /tmp/bazel-execroot/_main
1702418704.000854112: src/main/tools/linux-sandbox-pid1.cc:311: writable: /tmp
1702418704.000869304: src/main/tools/linux-sandbox-pid1.cc:311: writable: /dev/shm
1702418704.000876579: src/main/tools/linux-sandbox-pid1.cc:327: working dir: /tmp/bazel-working-directory/_main
1702418704.000949533: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /
1702418704.000959313: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /dev
1702418704.000963615: src/main/tools/linux-sandbox-pid1.cc:405: remount rw: /dev/shm
1702418704.000967575: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /dev/pts
1702418704.000971798: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /dev/hugepages
1702418704.000975643: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /dev/mqueue
1702418704.000979660: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /proc
1702418704.000993590: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /sys
1702418704.001141631: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /run
1702418704.001206959: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /var
1702418704.001215631: src/main/tools/linux-sandbox-pid1.cc:405: remount rw: /tmp
<unrelated paths snipped>
1702418704.002958323: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-execroot
1702418704.002966211: src/main/tools/linux-sandbox-pid1.cc:427: remount(nullptr, /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-execroot, nullptr, 2101281, nullptr) failure (No such file or directory) ignored
1702418704.002970402: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-working-directory
1702418704.002972290: src/main/tools/linux-sandbox-pid1.cc:427: remount(nullptr, /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-working-directory, nullptr, 2101281, nullptr) failure (No such file or directory) ignored
1702418704.002974770: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-source-roots/0
1702418704.002976413: src/main/tools/linux-sandbox-pid1.cc:427: remount(nullptr, /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-source-roots/0, nullptr, 2101281, nullptr) failure (No such file or directory) ignored
1702418704.002988558: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-source-roots/1
1702418704.002990230: src/main/tools/linux-sandbox-pid1.cc:427: remount(nullptr, /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-source-roots/1, nullptr, 2101281, nullptr) failure (No such file or directory) ignored
1702418704.002997175: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-source-roots/2
1702418704.002998951: src/main/tools/linux-sandbox-pid1.cc:427: remount(nullptr, /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-source-roots/2, nullptr, 2101281, nullptr) failure (No such file or directory) ignored
1702418704.003001364: src/main/tools/linux-sandbox-pid1.cc:405: remount rw: /tmp
1702418704.003004727: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /tmp/bazel-execroot
1702418704.003008764: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /tmp/bazel-working-directory
1702418704.003012225: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /tmp/bazel-source-roots/0
1702418704.003015831: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /tmp/bazel-source-roots/1
1702418704.003029328: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /tmp/bazel-source-roots/2
1702418704.003033205: src/main/tools/linux-sandbox-pid1.cc:405: remount rw: /tmp/bazel-execroot/_main
1702418704.003036504: src/main/tools/linux-sandbox-pid1.cc:405: remount rw: /tmp
1702418704.003039277: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /tmp/bazel-execroot
1702418704.003042065: src/main/tools/linux-sandbox-pid1.cc:405: remount rw: /tmp/bazel-execroot/_main
1702418704.003044940: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /tmp/bazel-working-directory
1702418704.003047774: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /tmp/bazel-source-roots/0
1702418704.003050505: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /tmp/bazel-source-roots/1
1702418704.003057570: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /tmp/bazel-source-roots/2
1702418704.003060582: src/main/tools/linux-sandbox-pid1.cc:405: remount rw: /dev/shm
1702418704.003064295: src/main/tools/linux-sandbox-pid1.cc:405: remount rw: /tmp/bazel-working-directory/_main
1702418704.003087515: src/main/tools/linux-sandbox-pid1.cc:496: calling fork...
1702418704.003209294: src/main/tools/linux-sandbox-pid1.cc:533: child started with PID 2
1702418704.005588552: src/main/tools/linux-sandbox-pid1.cc:550: wait returned pid=2, status=0x100
1702418704.005591954: src/main/tools/linux-sandbox-pid1.cc:568: child exited normally with code 1
1702418704.034940719: src/main/tools/linux-sandbox.cc:243: child exited normally with code 1

Inspecting the mounts and their ordering above confirms that contents in Bazel source roots and execroot should be visible: these mounts are bind mounted into the hermetic tmp location (not /tmp directly) before /tmp is pivoted to the hermetic tmp location (the final bind mount: in the above).


By altering the linux-sandbox invocation above we can confirm that the bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libanalysis_cluster-hjar.jar-0.params file is a dangling symlink, within the sandbox:

/tmp/bazel-rrbutani/install/89a68939cbf63eb54205fdf943a58b15/linux-sandbox \
    -W /tmp/bazel-working-directory/_main \
    -t 15 \
    -w /tmp/bazel-execroot/_main \
    -w /tmp \
    -w /dev/shm \
    -M /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/execroot \
        -m /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-execroot \
    -M /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/execroot \
        -m /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-working-directory \
    -M /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/external/rules_java~7.3.1~toolchains~remote_java_tools_linux \
        -m /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-source-roots/0 \
    -M /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/external/rules_java~7.3.1~toolchains~remotejdk21_linux \
        -m /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-source-roots/1 \
    -M /src/dev/bazel \
        -m /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp/bazel-source-roots/2 \
    -M /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/_hermetic_tmp \
        -m /tmp \
    -S /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/stats.out \
    -D /dev/null \
    -- ls --color -l bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libanalysis_cluster-hjar.jar-0.params
lrwxrwxrwx 1 rrbutani users 179 Dec 12 14:05 bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libanalysis_cluster-hjar.jar-0.params -> /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/execroot/_main/bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libanalysis_cluster-hjar.jar-0.params

Inspecting bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libanalysis_cluster-hjar.jar-0.params within this action's execroot (/tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/execroot/) confirms that the file is a symlink that refers to the host's execroot path rather than that of the sandbox (i.e. /tmp/bazel-execroot/):

ls /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/execroot/_main/bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libanalysis_cluster-hjar.jar-0.params -l
lrwxrwxrwx 1 rrbutani users 179 Dec 12 14:05 /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/execroot/_main/bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libanalysis_cluster-hjar.jar-0.params -> /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/execroot/_main/bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libanalysis_cluster-hjar.jar-0.paramsls /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3031/execroot/_main/bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/ -l | head
total 16
drwxr-x--- 2 rrbutani users 4096 Dec 12 14:05 libactions
lrwxrwxrwx 1 rrbutani users  128 Dec 12 14:05 libactions_provider-hjar.jar -> /tmp/bazel-execroot/_main/bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libactions_provider-hjar.jar
lrwxrwxrwx 1 rrbutani users  179 Dec 12 14:05 libanalysis_cluster-hjar.jar-0.params -> /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/execroot/_main/bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libanalysis_cluster-hjar.jar-0.params
lrwxrwxrwx 1 rrbutani users  141 Dec 12 14:05 libaspect_aware_attribute_mapper-hjar.jar -> /tmp/bazel-execroot/_main/bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libaspect_aware_attribute_mapper-hjar.jar
lrwxrwxrwx 1 rrbutani users  129 Dec 12 14:05 libaspect_collection-hjar.jar -> /tmp/bazel-execroot/_main/bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libaspect_collection-hjar.jar
lrwxrwxrwx 1 rrbutani users  130 Dec 12 14:05 libblaze_version_info-hjar.jar -> /tmp/bazel-execroot/_main/bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libblaze_version_info-hjar.jar
lrwxrwxrwx 1 rrbutani users  134 Dec 12 14:05 libbuild_setting_provider-hjar.jar -> /tmp/bazel-execroot/_main/bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libbuild_setting_provider-hjar.jar
drwxr-x--- 3 rrbutani users 4096 Dec 12 14:05 libconfig
lrwxrwxrwx 1 rrbutani users  129 Dec 12 14:05 libconfigured_target-hjar.jar -> /tmp/bazel-execroot/_main/bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libconfigured_target-hjar.jar

(note how the other files in the above are symlinks to /tmp/bazel-execroot/)

Cause

Poking around a bit, I think this is the relevant part of rules_java:

/* commandLines= */ CommandLines.builder()
.addCommandLine(executableLine)
.addCommandLine(commandLine.build(), PARAM_FILE_INFO)
.build(),

Notably rules_cc generated param files for link actions do not seem to have this issue (note the /tmp/bazel-execroot in the destinations):

fd . /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/ | grep params | xargs ls -l --color
lrwxrwxrwx 1 rrbutani users 179 Dec 12 14:25 /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3006/execroot/_main/bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libanalysis_cluster-hjar.jar-0.params -> /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/execroot/_main/bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/analysis/libanalysis_cluster-hjar.jar-0.params
lrwxrwxrwx 1 rrbutani users  80 Dec 12 14:27 /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3098/execroot/_main/bazel-out/k8-dbg/bin/src/main/tools/daemonize-2.params -> /tmp/bazel-execroot/_main/bazel-out/k8-dbg/bin/src/main/tools/daemonize-2.params
lrwxrwxrwx 1 rrbutani users  83 Dec 12 14:27 /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3114/execroot/_main/bazel-out/k8-dbg/bin/src/main/tools/liblogging.a-2.params -> /tmp/bazel-execroot/_main/bazel-out/k8-dbg/bin/src/main/tools/liblogging.a-2.params
lrwxrwxrwx 1 rrbutani users 111 Dec 12 14:27 /tmp/bazel-rrbutani/705c9771f27ae01ebf0993be3b99a716/sandbox/linux-sandbox/3149/execroot/_main/bazel-out/k8-dbg/bin/src/main/java/net/starlark/java/eval/libcpu_profiler.so-2.params -> /tmp/bazel-execroot/_main/bazel-out/k8-dbg/bin/src/main/java/net/starlark/java/eval/libcpu_profiler.so-2.params

I think that's because rules_cc generates its param files (for link actions) on its own using separate actions + files that are added as dependencies and doesn't use the CommandLines.Builder machinery:

if (linkCommandLine.getParamFile() != null) {
inputsBuilder.add(linkCommandLine.getParamFile());
// Pass along tree artifacts, so they can be properly expanded.
NestedSet<Artifact> paramFileActionInputs =
NestedSetBuilder.wrap(
Order.STABLE_ORDER,
Iterables.filter(expandedLinkerArtifacts.toList(), Artifact::isTreeArtifact));
ParameterFile.ParameterFileType quoting =
featureConfiguration.isEnabled(CppRuleClasses.GCC_QUOTING_FOR_PARAM_FILES)
? ParameterFile.ParameterFileType.GCC_QUOTED
: ParameterFile.ParameterFileType.UNQUOTED;
Action parameterFileWriteAction =
new ParameterFileWriteAction(
getOwner(),
paramFileActionInputs,
paramFile,
linkCommandLine.paramCmdLine(),
quoting);
actionConstructionContext.registerAction(parameterFileWriteAction);
}


I am not familiar with this part of the Bazel codebase but it seems likely the problematic bit (placing host-execroot paths for the params file onto the command line) lives here:

if (useParamFile) {
PathFragment paramFileExecPath =
ParameterFile.derivePath(paramFileBasePath, Integer.toString(paramFileNameSuffix));
++paramFileNameSuffix;
String paramArg =
SingleStringArgFormatter.format(
paramFileInfo.getFlagFormatString(),
pathMapper.map(paramFileExecPath).getPathString());
arguments.addElement(paramArg);
cmdLineLength += paramArg.length() + 1;
if (paramFileInfo.flagsOnly()) {
// Move just the flags into the file, and keep the positional parameters on the command
// line.
paramFiles.add(
new ParamFileActionInput(
paramFileExecPath,
ParameterFile.flagsOnly(args),
paramFileInfo.getFileType(),
paramFileInfo.getCharset()));
for (String positionalArg : ParameterFile.nonFlags(args)) {
arguments.addElement(positionalArg);
cmdLineLength += positionalArg.length() + 1;
}
} else {
paramFiles.add(
new ParamFileActionInput(
paramFileExecPath,
args,
paramFileInfo.getFileType(),
paramFileInfo.getCharset()));
}
}

And here:

ExpandedCommandLines expandedCommandLines =
commandLines.expand(
artifactExpander, getPrimaryOutput().getExecPath(), pathMapper, getCommandLineLimits());
return new ActionSpawn(
ImmutableList.copyOf(expandedCommandLines.arguments()),
this,
env,
envResolved,
getInputs(),
expandedCommandLines.getParamFiles(),
filesetMappings,
reportOutputs,
pathMapper);

(note the use of getPrimaryOutput().getExecPath() for paramFileBasePath)

@fmeum
Copy link
Collaborator

fmeum commented Dec 12, 2023

Thanks for the highly detailed report! I will look into this tomorrow.

Cc @lberki

@lberki
Copy link
Contributor

lberki commented Dec 13, 2023

Woah, that was a very detailed report, thanks for investing the time and energy into it :) It helped me to zero in on the problem:

I can reproduce this. It's due to this snippet:

} else if (actionInput instanceof Artifact) {

It doesn't recognize VirtualActionInputs as something in the execroot, therefore, it doesn't transform its root to /tmp/bazel-execroot. Let me see if I can fix this with a well-aimed tiny change (I probably won't have the time to put together a test case, though)

@lberki
Copy link
Contributor

lberki commented Dec 13, 2023

The good news is that this tiny patch:

diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxHelpers.java b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxHelpers.java
index fb72d591e0..845d69be7b 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxHelpers.java
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxHelpers.java
@@ -503,6 +503,8 @@ public final class SandboxHelpers {

         if (actionInput instanceof EmptyActionInput) {
           inputPath = null;
+        } else if (actionInput instanceof VirtualActionInput) {
+          inputPath = RootedPath.toRootedPath(withinSandboxExecRoot, actionInput.getExecPath());
         } else if (actionInput instanceof Artifact) {
           Artifact inputArtifact = (Artifact) actionInput;
           if (inputArtifact.isSourceArtifact() && sandboxSourceRoots != null) {

fixes the issue with the params files. The bad news is that it's still not working, but the deploy jar creation (which is the action that fails for me) now fails with a different error. I probably won't have time to debug this any further today.

@lberki
Copy link
Contributor

lberki commented Dec 13, 2023

Reproduction:

touch WORKSPACE
mkdir -p java/a

cat > java/a/BUILD <<'EOF'
java_library(
    name = "a",
    srcs = ["A.java"],
)

java_binary(
    name = "b",
    srcs = ["B.java"],
    deps = [":a"],
)
EOF

cat > java/a/A.java <<'EOF'
package a;

public class A {
  public static int getValue() {
    return 3;
  }
}
EOF

cat > java/a/B.java <<'EOF'
import a.A;

public class B {
  public static void main(String[] args) {
    System.err.println(A.getValue());
  }
}
EOF

bazel --output_base=/tmp/ob build //java/a:b_deploy.jar

@fmeum
Copy link
Collaborator

fmeum commented Dec 13, 2023

I continued debugging @lberki's reproducer and it turns out that the next issue is most likely #20518, given that the failure points to this file:

actions.symlink(output = output_redacted_file, target_file = redacted_file)

@lberki
Copy link
Contributor

lberki commented Dec 13, 2023

@fmeum I think you're right -- I didn't get even far enough to find out that the missing file is a symlink but it indeed is.

@bcsgh
Copy link

bcsgh commented Dec 18, 2023

BTW: I'm running it either this issue or a very similar one showing up when external/bazel_tools/tools/test/generate-xml.sh tries to run:

$ bazel --output_base=$(mktemp -d -t tmp-bazel-base-XXXXXXXXXX) test //:some_test --sandbox_debug
[...]
1702872574.903264941: src/main/tools/linux-sandbox-pid1.cc:302: bind mount: /tmp/tmp-bazel-base-ms8mQWfOXq/sandbox/linux-sandbox/162/_hermetic_tmp -> /tmp
1702872574.903285799: src/main/tools/linux-sandbox-pid1.cc:311: writable: /tmp/bazel-execroot/wd
[...]
1702872574.973004420: src/main/tools/linux-sandbox-pid1.cc:302: bind mount: /tmp/tmp-bazel-base-ms8mQWfOXq/sandbox/linux-sandbox/163/_hermetic_tmp -> /tmp
1702872574.973021869: src/main/tools/linux-sandbox-pid1.cc:311: writable: /tmp/bazel-execroot/wd
[...]
ERROR: /home/bcs/wd/BUILD:9:12: Testing //:some_test failed: (Exit 1): linux-sandbox failed: error executing TestRunner command 
  (cd /tmp/tmp-bazel-base-ms8mQWfOXq/sandbox/linux-sandbox/163/execroot/wd && \
[...]
  /home/bcs/.cache/bazel/_bazel_bcs/install/89a68939cbf63eb54205fdf943a58b15/linux-sandbox \
   -W /tmp/bazel-working-directory/wd \
   -t 15 \
   -w /tmp/bazel-execroot/wd \
   -w /tmp/tmp-bazel-base-ms8mQWfOXq/sandbox/linux-sandbox/163/execroot/wd/_tmp/270135f98d0932ba0f76c9b90a5c8ea3 \
   -w /tmp \
   -w /dev/shm \
   -M /tmp/tmp-bazel-base-ms8mQWfOXq/execroot \
   -m /tmp/tmp-bazel-base-ms8mQWfOXq/sandbox/linux-sandbox/163/_hermetic_tmp/bazel-execroot \
   -M /tmp/tmp-bazel-base-ms8mQWfOXq/sandbox/linux-sandbox/163/execroot \
   -m /tmp/tmp-bazel-base-ms8mQWfOXq/sandbox/linux-sandbox/163/_hermetic_tmp/bazel-working-directory \
   -M /tmp/tmp-bazel-base-ms8mQWfOXq/external/bazel_tools \
   -m /tmp/tmp-bazel-base-ms8mQWfOXq/sandbox/linux-sandbox/163/_hermetic_tmp/bazel-source-roots/0 \
   -M /tmp/tmp-bazel-base-ms8mQWfOXq/sandbox/linux-sandbox/163/_hermetic_tmp \
   -m /tmp \
   -S /tmp/tmp-bazel-base-ms8mQWfOXq/sandbox/linux-sandbox/163/stats.out \
   -D /tmp/tmp-bazel-base-ms8mQWfOXq/sandbox/linux-sandbox/163/debug.out \
   -- \
   external/bazel_tools/tools/test/generate-xml.sh \
      bazel-out/k8-fastbuild/testlogs/some_test/test.log \
      bazel-out/k8-fastbuild/testlogs/some_test/test.xml 0 1)
[...]
$ ll /tmp/tmp-bazel-base-ms8mQWfOXq/sandbox/linux-sandbox/163/execroot/wd/external/bazel_tools/tools/test/generate-xml.sh

Every path starting with /tmp that isn't under /tmp/tmp-bazel-base-ms8mQWfOXq/ seems to be wrong. I'm seeing at least these three:

  • /tmp
  • /tmp/bazel-working-directory/
  • /tmp/bazel-execroot/

@fmeum
Copy link
Collaborator

fmeum commented Dec 18, 2023

@bazel-io flag

@bazel-io bazel-io added the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Dec 18, 2023
@iancha1992
Copy link
Member

@bazel-io fork 7.1.0

@fmeum
Copy link
Collaborator

fmeum commented Dec 19, 2023

@iancha1992 Forget to say that we should really have this target 7.0.1 - maybe not the full fix, but something that makes the default configuration work with it.

@lberki
Copy link
Contributor

lberki commented Dec 19, 2023

#20603 is a draft fix for this (it contains the aforementioned two-line change and the more involved fix for #20518)

@tjgq tjgq removed the untriaged label Jan 2, 2024
bazel-io pushed a commit to bazel-io/bazel that referenced this issue Jan 2, 2024
…sted themselves when the output base was under `/tmp`:

1. Virtual action inputs didn't work. This was a fairly simple omission in the path transformation logic.
2. Artifacts which are resolved symlinks (i.e. declared using `declare_file`) did not work. This is fixed by keeping track of the realpath of the symlink in `FileArtifactValue` / `TreeArtifactValue`.

Fixes bazelbuild#20515 and bazelbuild#20518.

RELNOTES: None.
PiperOrigin-RevId: 595145191
Change-Id: I833025928374c78bc719d8e3be1efb2b2950b9f1
bazel-io pushed a commit to bazel-io/bazel that referenced this issue Jan 2, 2024
…sted themselves when the output base was under `/tmp`:

1. Virtual action inputs didn't work. This was a fairly simple omission in the path transformation logic.
2. Artifacts which are resolved symlinks (i.e. declared using `declare_file`) did not work. This is fixed by keeping track of the realpath of the symlink in `FileArtifactValue` / `TreeArtifactValue`.

Fixes bazelbuild#20515 and bazelbuild#20518.

RELNOTES: None.
PiperOrigin-RevId: 595145191
Change-Id: I833025928374c78bc719d8e3be1efb2b2950b9f1
iancha1992 pushed a commit that referenced this issue Jan 3, 2024
…manifested themselves when the output base was under /tmp (#20718)

1. Virtual action inputs didn't work. This was a fairly simple omission
in the path transformation logic.
2. Artifacts which are resolved symlinks (i.e. declared using
`declare_file`) did not work. This is fixed by keeping track of the
realpath of the symlink in `FileArtifactValue` / `TreeArtifactValue`.

Fixes #20515 and #20518.

RELNOTES: None.
Commit
fb6658c

PiperOrigin-RevId: 595145191
Change-Id: I833025928374c78bc719d8e3be1efb2b2950b9f1

Co-authored-by: Googler <lberki@google.com>
bazel-io pushed a commit to bazel-io/bazel that referenced this issue Jan 5, 2024
…sted themselves when the output base was under `/tmp`:

1. Virtual action inputs didn't work. This was a fairly simple omission in the path transformation logic.
2. Artifacts which are resolved symlinks (i.e. declared using `declare_file`) did not work. This is fixed by keeping track of the realpath of the symlink in `FileArtifactValue` / `TreeArtifactValue`.

Fixes bazelbuild#20515 and bazelbuild#20518.

RELNOTES: None.
PiperOrigin-RevId: 595145191
Change-Id: I833025928374c78bc719d8e3be1efb2b2950b9f1
github-merge-queue bot pushed a commit that referenced this issue Jan 8, 2024
…manifested themselves when the output base was under /tmp (#20766)

1. Virtual action inputs didn't work. This was a fairly simple omission
in the path transformation logic.
2. Artifacts which are resolved symlinks (i.e. declared using
`declare_file`) did not work. This is fixed by keeping track of the
realpath of the symlink in `FileArtifactValue` / `TreeArtifactValue`.

Fixes #20515 and #20518.

RELNOTES: None.
Commit
fb6658c

PiperOrigin-RevId: 595145191
Change-Id: I833025928374c78bc719d8e3be1efb2b2950b9f1

Co-authored-by: Googler <lberki@google.com>
@iancha1992
Copy link
Member

A fix for this issue has been included in Bazel 7.1.0 RC1. Please test out the release candidate and report any issues as soon as possible. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Local-Exec Issues and PRs for the Execution (Local) team type: bug
Projects
None yet
Development

No branches or pull requests

9 participants