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

Piping to "head -n1" generates a panic (not handling SIGPIPE?) #20

Open
Horgix opened this issue Jun 26, 2019 · 1 comment
Open

Piping to "head -n1" generates a panic (not handling SIGPIPE?) #20

Horgix opened this issue Jun 26, 2019 · 1 comment
Labels
bug Something isn't working

Comments

@Horgix
Copy link
Contributor

Horgix commented Jun 26, 2019

The second part of the "smoke test" step in the CircleCI pipeline was this command :

command: ./xebia-cli --help | head -n1 | grep xebia-cli`

It essentially just ran the CLI, got the first line which is supposed to look like xebia-cli X.Y thanks to clap and the cli.yml. It was recently disable because of a flaw that will take a bit of time to figure out and to fix.

Indeed, piping the output of xebia-cli to head -n1 makes it panic:

thread 'main' panicked at 'Error writing Error to stdout: Os { code: 32, kind: BrokenPipe, message: "Broken pipe" }', src/libcore/result.rs:997:5

It's not related in any way to our code and is totally reproducable with the following snippet only:

extern crate log;
extern crate simplelog;
use simplelog::*;

extern crate clap;
use clap::App;

fn main() {
    // Initialize logging
    let term_logger = match TermLogger::new(LevelFilter::Debug, Config::default()) {
        Some(tl) => tl,
        None => {
            println!("Failed to create TermLogger; exiting.");
            std::process::exit(1);
        }
    };
    CombinedLogger::init(vec![term_logger]).expect("Failed to initialize logger");

    // Reproduce bug
    log::debug!("Here is a crash");
    let _matches = App::new("simplelog-broken-pipe-demo").get_matches();
}

Building with and running it followed by a | head -n1 will result in the same crash.

Surprisingly, piping it to grep or a simple head without -n is not crashing the application.

This definitely has to be investigated, may it be only to discover WTF is going on here. It may be related to SIGPIPE being sent to the binary when a pipe is stopped brutally, which is not handled by Rust.

Some references of a first look at this issue:

@Horgix Horgix added the bug Something isn't working label Jun 26, 2019
@Horgix Horgix changed the title Piping the stdout generates a panic Piping to "head -n1" generates a panic (not handling SIGPIPE?) Jun 26, 2019
@Horgix
Copy link
Contributor Author

Horgix commented Jun 26, 2019

The CircleCI step using | head -n has been disabled in c0eeb96

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant