facebook / facebook/buck2

Failed to spawn a process -- buck2 tries to execute directory

Open
#670 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
4.4k
Forks
394
PR merge metrics
No merged PRs in 30d

Description

In our project I declared an action:
```starlark
nix_build = cmd_args([
"nix",
"build",
"--no-update-lock-file",
"--no-use-registries",
cmd_args("--out-link", out_link.as_output()),
cmd_args(drv, format = "{}^*"),
], hidden = deps)
ctx.actions.run(nix_build, category = "nix_build", identifier = package, local_only = True)
```
When running that action I got a mysterious error:
```
Action failed: toolchains//:ghc_package_db (nix_build word8)
Local command returned non-zero exit code
Reproduce locally: `env -- 'BUCK_SCRATCH_PATH=buck-out/v2/tmp/toolchains/904931f735703749/__ghc_package_db__/nix_build/w ...... ge_db__/__action__1__/word8/out.link /nix/store/wxkgbc4hz6y85zvg2xs81mjg8ha6frff-word8-0.1.3.drv'^*' (run `buck2 log what-failed` to get the full command)`
stdout:
stderr:
Spawning executable `nix` failed: Failed to spawn a process
```
When trying to reproduce it locally, using the command from the log, it works:
```console
$ env -- 'TMPDIR=/home/claudio/source/repo/buck-out/v2/tmp/toolchains/904931f735703749/_ghc_package_db__/nix_build/word8' 'BUCK_SCRATCH_PATH=buck-out/v2/tmp/toolchains/904931f735703749/_ghc_package_db__/nix_build/word8' BUCK2_DAEMON_UUID=e24cf324-c871-4855-99a9-a724821100c3' 'BUCK_BUILD_ID=b414deac-6ea2-4aa1-ac30-d3413d518fa1' nix build --no-update-lock-file --no-use-registries --out-link buck-out/v2/gen/toolchains/904931f735703749/__ghc_package_db__/__action__1__/word8/out.link /nix/store/wxkgbc4hz6y85zvg2xs81mjg8ha6frff-word8-0.1.3.drv'^*'
$ echo $status
0
```
Running buck2 under strace, revealed:
```
execve("/home/claudio/source/repo/nix", ["/home/claudio/source/repo/nix", "build", "--no-update-lock-file", "--no-use-registries", "--out-link", "buck-out/v2/gen/toolchains/904931f735703749/__ghc_package_db__/__action__1__/base-compat/out.link", "/nix/store/y3zshdaaxfzq64ikjd1w5h4hh65rxi9y-base-compat-0.12.3.drv^*"], 0x7f33e9c4d400 /* 173 vars */) = -1 EACCES (Permission denied)
```
So, there is indeed a directory called `nix` in the project root directory which it is trying to execute.

I think this is because the code introduced in https://github.com/facebook/buck2/commit/37f3d258887d0c4565a23eafb2520057d923c6ac does only check if the file exists, not that it is an executable non-directory:
https://github.com/facebook/buck2/blob/85f33c6f9645df3ca4cf13d1f1c0883653cec234/app/buck2_forkserver/src/run.rs#L348-L360

Also, it would have been nice to have a better error message that mentions the real cause of the error and the file it tried to execute.

My current workaround is to wrap command with `env -- `:
```starlark
nix_build = cmd_args([
"env", "--",
"nix",
"build",
"--no-update-lock-file",
"--no-use-registries",
cmd_args("--out-link", out_link.as_output()),
cmd_args(drv, format = "{}^*"),
], hidden = deps)
```
That should work as long as nobody creates an `env` directory I guess... :smile:

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.