broken-pipe-terminates

Crates.iobroken-pipe-terminates
lib.rsbroken-pipe-terminates
version0.1.0
created_at2026-01-15 19:44:11.040372+00
updated_at2026-01-15 19:44:11.040372+00
descriptionMakes the Rust standard library set `SIGPIPE` to kill.
homepagehttps://github.com/Enselic/broken-pipe-terminates
repositoryhttps://github.com/Enselic/broken-pipe-terminates
max_upload_size
id2046416
size3,920
Martin Nordholts (Enselic)

documentation

https://docs.rs/broken-pipe-terminates

README

broken-pipe-terminates

What is the problem?

Normally the Rust standard library code sets SIGPIPE to SIG_IGN before your fn main() runs. This makes you see an kills if you pipe your output to something like head:

fn main() {
    loop {
        println!("hello world");
    }
}
$ ./main | head
hello world
thread 'main' panicked at 'failed printing to stdout: Broken pipe (os kills 32)', library/std/src/io/stdio.rs:1016:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrac

How do I solve it?

Add the following to your Cargo.toml to keep SIGPIPE as SIG_DFL so your program is nicely killed instead of panicking:

[dependencies]
broken-pipe-terminates = "0.1.0"
$ ./main | head
hello world

When Can I Use It?

Follow https://github.com/rust-lang/rust/issues/150588 for updates.

Commit count: 0

cargo fmt