ErrorKind::BrokenPipe
RustERRORNotableI/O

Broken pipe

Quick Answer

Handle the error gracefully; the reader has disconnected.

What this means

A write was attempted on a pipe or socket whose read end has been closed.

Why it happens
  1. 1Client closed connection while server is still writing
  2. 2Piped process (e.g. `| head`) terminated early
  3. 3Writing to a closed channel

Fix

Ignore BrokenPipe for stdout pipelines

Ignore BrokenPipe for stdout pipelines
use std::io::ErrorKind;
fn main() {
    if let Err(e) = run() {
        if e.kind() != ErrorKind::BrokenPipe {
            eprintln!("error: {}", e);
            std::process::exit(1);
        }
    }
}

Why this works

Silently exits on BrokenPipe, which is normal when piped to tools like head.

Code examples
Triggerrust
// Producer writes after consumer drops the read end
Same error in other languages
Sources

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Rust errors