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

grep: write error: Broken pipe when running tests #115

Closed
Pamplemousse opened this issue Mar 7, 2024 · 2 comments
Closed

grep: write error: Broken pipe when running tests #115

Pamplemousse opened this issue Mar 7, 2024 · 2 comments

Comments

@Pamplemousse
Copy link
Contributor

When running tests in a "non-conventional" environment (during a nix build), I noticed that some complain about a broken pipe (but are still successful).

Running test_fail_fails ... /nix/store/11b3chszacfr9liy829xqknzp3q88iji-gnugrep-3.11/bin/grep: write error: Broken pipe
SUCCESS

I understand that 5d8953b9 addressed a similar issue.

Internet searches pointed at a potential culprit: SIGPIPE being trapped (which happens in nix build, and on - some - CI/CD environments).

And indeed, one can reproduce the complaint by manually trapping SIGPIPE:

$ trap '' SIGPIPE
$ ./bash_unit -p test_fail_fails tests/test_core.sh 
Running tests in tests/test_core.sh
        Running test_fail_fails ... /nix/store/11b3chszacfr9liy829xqknzp3q88iji-gnugrep-3.11/bin/grep: write error: Broken pipe
SUCCESS ✓ 
Overall result: SUCCESS ✓ 

It's unclear to me how this situation should be handled, especially as I am not sure which pipe(s) may break.

As far as I can tell, only the following tests behave this way:

test_assert_fails_fails
test_assert_shows_stderr_on_failure
test_assert_shows_stdout_on_failure
test_fail_fails
test_fail_prints_failure_message
@pgrange
Copy link
Owner

pgrange commented Mar 8, 2024

Interesting, thank you @Pamplemousse

About 5d8953b9, that you mention and that adresses the issue, the code also states:

  # I have no idea what is happening with these broken pipes on github actions

🤣

The fact that you managed to reproduce it locally should really help, thank you.

pgrange added a commit that referenced this issue Mar 8, 2024
We observed broken pipe output messages with bash_unit test in
some environments: github CI and nix builds. The tests are
passing but display this suspiscious error message.

@Pamplemousse has been able to reproduce them locally by trapping
SIGPIPE:

  # trap '' SIGPIPE
  # ./bash_unit -p test_fail_fails tests/test_core.sh
  Running tests in tests/test_core.sh
          Running test_fail_fails ... /nix/store/11b3chszacfr9liy829xqknzp3q88iji-gnugrep-3.11/bin/grep: write error: Broken pipe
  SUCCESS ✓
  Overall result: SUCCESS ✓

From man, SIGPIPE appears when a process writes on a pipe with
no reader. Looking at the problematic tests, we see that they
all rely on a muted bash_unit with a stacktrace output being
muted.

When we look at how the stacktrace is muted, the code was like this:

  notify_stack () { : ; }

And when we look at how the stacktrace is outputed by bash_unit we
see the following code:

  stacktrace | notify_stack

So we have some process run by stacktrace that is piped to a void
function, that is, no process on the right of this pipe is reading
which makes it a good candidate to generate a SIGPIPE.

By replacing the muted notify_stack with the following code, the
issue is solved:

  notify_stack  () { $CAT >/dev/null ; }
@pgrange pgrange closed this as completed in 800016b Mar 8, 2024
@pgrange
Copy link
Owner

pgrange commented Mar 8, 2024

Awesome, I've learned something here. Problem fixed, thank you @Pamplemousse

I know it'll come kick me in the knees some day but I've decided to not write a test case for this one as it's quite an edge case and, actually, was a but in the test code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants