Skip to content

tail: tests with piped input are failing randomly with broken pipe on macos when no output is expected #3895

@Joining7943

Description

@Joining7943

Here's the reference to the original discussion:

I did some more testing on macOS.
The failures will also sometimes (10-20% of the time) happen on the main branch.
However, they will only happen inside the test framework, i.e. this will never trigger a failure:

for i in {1..100}; do echo "a\nb\n" | target/debug/tail -n +3; done

but this will fail regularly:

let test_string = "a\nb\n";
new_ucmd!()
    .args(&["-n", "+3"])
    .pipe_in(test_string)
    .succeeds()
    .no_stdout()
    .no_stderr();

Originally posted by @jhscheer in #3874 (comment)

EDIT:
Here's the exact message from one of the failing tests during the CICD #8262 (https://github.com/uutils/coreutils/actions/runs/2939929799) run:

2022-08-27T20:38:23.8017460Z failures:
2022-08-27T20:38:23.8017780Z 
2022-08-27T20:38:23.8019590Z ---- test_tail::pipe_tests::test_pipe_when_negative_lines_option_given_no_newline_at_eof stdout ----
2022-08-27T20:38:23.8020010Z current_directory_resolved: 
2022-08-27T20:38:23.8021360Z run: /Users/runner/work/coreutils/coreutils/target/debug/coreutils tail -n 0
2022-08-27T20:38:23.8022960Z thread 'test_tail::pipe_tests::test_pipe_when_negative_lines_option_given_no_newline_at_eof' panicked at 'failed to write to stdin of child: Broken pi
pe (os error 32)', tests/common/util.rs:1115:21
2022-08-27T20:38:23.8023550Z 
2022-08-27T20:38:23.8023700Z 
2022-08-27T20:38:23.8023940Z failures:
2022-08-27T20:38:23.8024440Z     test_tail::pipe_tests::test_pipe_when_negative_lines_option_given_no_newline_at_eof
2022-08-27T20:38:23.8024840Z 
2022-08-27T20:38:23.8025270Z test result: FAILED. 1904 passed; 1 failed; 31 ignored; 0 measured; 0 filtered out; finished in 109.75s
2022-08-27T20:38:23.8025710Z 
2022-08-27T20:38:23.8097270Z error: test failed, to rerun pass '--test tests'
2022-08-27T20:38:23.8208890Z ##[error]The process '/Users/runner/.cargo/bin/cargo' failed with exit code 101

Looking at the code around tests/common/util.rs:1115 the child target/debug/coreutils tail -n 0 seams to have closed its stdin already when trying to write to its stdin. But maybe I'm wrong. Strange that it happens only on macos.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions