Running bazel in a subshell causes subshell to hang
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the bug:
This hangs. This only ends after I manually shutdown the server from another terminal window.
```
bazel shutdown;
( ( tools/bazel version ) | cat ) 3>&1 1>&2 2>&3 | cat
```
This only happens when the bazel server is started within a subshell within a subshell (hence the `bazel shutdown` at the beginning). I checked the process tree and the bazel server is attached to `systemd`, but the second `cat` still waits for the server to shutdown.
### Which category does this issue belong to?
Local Execution
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
```
bazel shutdown;
( ( tools/bazel version ) | cat ) 3>&1 1>&2 2>&3 | cat
```
OR, here's a simplified version of my original build command that causes the issue. I am trying to `tee` stdout and stderr to different files.
```
( ( bazel build //foo:bar ) | tee stdout.txt ) 3>&1 1>&2 2>&3 | tee stderr.txt
```
### Which operating system are you running Bazel on?
Linux
### What is the output of `bazel info release`?
development version
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
From https://cs.android.com/android/kernel/superproject/+/common-android-mainline:prebuilts/bazel/linux-x86_64/
### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?
```text
N/A
```
### Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.
Probably not
### Have you found anything relevant by searching the web?
_No response_
### Any other information, logs, or outputs that you want to share?
Workaround is to run `bazel version > /dev/null` right after `bazel shutdown` to start the bazel server not in a subshell.
Contributor guide
Research direction
Reproduce the issue on Linux using the nested `tools/bazel version` and `bazel build //foo:bar` pipeline commands, beginning with `bazel shutdown`. Trace the Bazel server startup and shutdown behavior in these subshells; done means the pipeline's final `cat` exits without a manual server shutdown, while preserving the separate stdout and stderr behavior shown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux, shell
- Domain
- build-system, cli, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100