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

Use less subshells and tees in running tests with bazel run. #17846

Closed
wants to merge 1 commit into from

Conversation

meisterT
Copy link
Member

Fixes #17754.

What we have seen prior to this change was that sometimes for quick tests the output was swallowed. After a lot of poking it became clear that the culprit is the use of subshell and tee, e.g. if you remove tee completely from the picture the behavior never shows up.

The issue is that with a fast test, tee seems to be killed (or its parent subshell) before the printing the output to stdout.

With this change, we reduce the number of subshells and processes to set up and reduce the chance of the race condition but not remove it.

However, for practical purposes, the race condition is gone.

With the reproduction steps in #17754, and this command

for i in {1..10000}; do /tmp/bazel run :foo &> /tmp/log ; grep -q "useful echo" /tmp/log ; if [ $? -eq 0 ]; then echo -n '+'; else  echo -n '-'; fi; done

a bazel from head fails ~3900 out of 10000 times.

After this commit, it never failed.

Fixes #17754.

What we have seen prior to this change was that sometimes for quick
tests the output was swallowed. After a lot of poking it became clear
that the culprit is the use of subshell and `tee`, e.g. if you remove
`tee` completely from the picture the behavior never shows up.

The issue is that with a fast test, `tee` seems to be killed (or its
parent subshell) before the printing the output to stdout.

With this change, we reduce the number of subshells and processes to set
up and reduce the chance of the race condition but not remove it.

However, for practical purposes, the race condition is gone.

With the reproduction steps in #17754, and this command
```
for i in {1..10000}; do /tmp/bazel run :foo &> /tmp/log ; grep -q "useful echo" /tmp/log ; if [ $? -eq 0 ]; then echo -n '+'; else  echo -n '-'; fi; done
```
a bazel from head fails ~3900 out of 10000 times.

After this commit, it never failed.
@ShreeM01 ShreeM01 added awaiting-review PR is awaiting review from an assigned reviewer team-CLI Console UI labels Mar 22, 2023
@fmeum
Copy link
Collaborator

fmeum commented Mar 23, 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 Mar 23, 2023
@keertk
Copy link
Member

keertk commented Mar 23, 2023

@bazel-io fork 6.2.0

@bazel-io bazel-io removed the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Mar 23, 2023
ShreeM01 pushed a commit to ShreeM01/bazel that referenced this pull request Mar 23, 2023
Fixes bazelbuild#17754.

What we have seen prior to this change was that sometimes for quick tests the output was swallowed. After a lot of poking it became clear that the culprit is the use of subshell and `tee`, e.g. if you remove `tee` completely from the picture the behavior never shows up.

The issue is that with a fast test, `tee` seems to be killed (or its parent subshell) before the printing the output to stdout.

With this change, we reduce the number of subshells and processes to set up and reduce the chance of the race condition but not remove it.

However, for practical purposes, the race condition is gone.

With the reproduction steps in bazelbuild#17754, and this command
```
for i in {1..10000}; do /tmp/bazel run :foo &> /tmp/log ; grep -q "useful echo" /tmp/log ; if [ $? -eq 0 ]; then echo -n '+'; else  echo -n '-'; fi; done
```
a bazel from head fails ~3900 out of 10000 times.

After this commit, it never failed.

Closes bazelbuild#17846.

PiperOrigin-RevId: 518794237
Change-Id: I8c1862d3a274799b864f0f5f42b85d6df5af78c7
ShreeM01 added a commit that referenced this pull request Mar 24, 2023
)

Fixes #17754.

What we have seen prior to this change was that sometimes for quick tests the output was swallowed. After a lot of poking it became clear that the culprit is the use of subshell and `tee`, e.g. if you remove `tee` completely from the picture the behavior never shows up.

The issue is that with a fast test, `tee` seems to be killed (or its parent subshell) before the printing the output to stdout.

With this change, we reduce the number of subshells and processes to set up and reduce the chance of the race condition but not remove it.

However, for practical purposes, the race condition is gone.

With the reproduction steps in #17754, and this command
```
for i in {1..10000}; do /tmp/bazel run :foo &> /tmp/log ; grep -q "useful echo" /tmp/log ; if [ $? -eq 0 ]; then echo -n '+'; else  echo -n '-'; fi; done
```
a bazel from head fails ~3900 out of 10000 times.

After this commit, it never failed.

Closes #17846.

PiperOrigin-RevId: 518794237
Change-Id: I8c1862d3a274799b864f0f5f42b85d6df5af78c7

Co-authored-by: Tobias Werth <twerth@google.com>
fweikert pushed a commit to fweikert/bazel that referenced this pull request May 25, 2023
Fixes bazelbuild#17754.

What we have seen prior to this change was that sometimes for quick tests the output was swallowed. After a lot of poking it became clear that the culprit is the use of subshell and `tee`, e.g. if you remove `tee` completely from the picture the behavior never shows up.

The issue is that with a fast test, `tee` seems to be killed (or its parent subshell) before the printing the output to stdout.

With this change, we reduce the number of subshells and processes to set up and reduce the chance of the race condition but not remove it.

However, for practical purposes, the race condition is gone.

With the reproduction steps in bazelbuild#17754, and this command
```
for i in {1..10000}; do /tmp/bazel run :foo &> /tmp/log ; grep -q "useful echo" /tmp/log ; if [ $? -eq 0 ]; then echo -n '+'; else  echo -n '-'; fi; done
```
a bazel from head fails ~3900 out of 10000 times.

After this commit, it never failed.

Closes bazelbuild#17846.

PiperOrigin-RevId: 518794237
Change-Id: I8c1862d3a274799b864f0f5f42b85d6df5af78c7
@Wyverald Wyverald deleted the bazelrunomit branch July 14, 2023 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review PR is awaiting review from an assigned reviewer team-CLI Console UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Running shell tests with bazel run intermittently omits outputs
5 participants