#931·hyperfine

hyperfine panics on broken pipe (EPIPE) for all run-output paths

Author: MathjkCreated Sep 30, 2026Updated Sep 30, 2026

Bug description

Hyperfine panics when its standard output stream is closed while benchmark results are being printed — e.g. when piping to a program that exits early:

$ hyperfine --runs 1 "echo hi" | head -n 0
thread 'main' (1234) panicked at library/std/src/io/stdio.rs:1166:9:
failed printing to stdout: Broken pipe (os error 32)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

(exit code 101)

This affects every code path that prints results to stdout:

  • the Benchmark N: … header and Time/Range result lines (src/benchmark/mod.rs)
  • the Summary / Relative speed comparison tables (src/benchmark/scheduler.rs)
  • export to stdout via --export-json -, --export-markdown -, etc. (src/export/mod.rs, ExportTarget::Stdout)

This is the same bug class as #453, which was closed by fixing only the -h/--help output (handled inside clap). All println! sites reachable during an actual benchmark run still panic on EPIPE (Unix) / ERROR_BROKEN_PIPE (Windows).

Unix command-line tools conventionally terminate quietly when their output pipe is closed (they die from SIGPIPE). Rust ignores SIGPIPE, so the write error surfaces as a panic in println! instead.

Expected behavior

hyperfine … | head -n 0 should terminate quietly without a panic message, the same as other CLI tools.

Steps to reproduce

On Unix, hyperfine --runs 1 "echo hi" | head -n 0 usually reproduces it (timing-dependent). Deterministic version, with the pipe's read end closed before spawn:

python
import os, subprocess
r, w = os.pipe()
os.close(r)
p = subprocess.Popen(["hyperfine", "--runs", "1", "echo hi"], stdout=w)
os.close(w)
p.wait()
print(p.returncode)  # 101, with the panic message on stderr

The same panic occurs for hyperfine --runs 1 --export-json - "echo hi", --export-markdown -, and for multiple commands (summary table). On Windows it was verified as hyperfine --runs 1 "cmd /c echo hi" | exit0.exe where exit0.exe exits immediately (panic with os error 232, ERROR_BROKEN_PIPE).

Suggested fix

Replace the println! calls that write to stdout with writeln!(io::stdout(), …) and propagate the io::Error (the surrounding functions already return Result or can return Result); then, in main(), treat io::ErrorKind::BrokenPipe as a quiet exit(0) — matching how e.g. Cargo and other CLI tools handle a closed output stream. A candidate patch implementing this, including a regression test that runs hyperfine with a pre-closed stdout pipe, is available on my fork (fix/broken-pipe branch, https://github.com/Mathjk/hyperfine/tree/fix/broken-pipe). It also converts the eprintln! warning paths to error-propagating writeln! calls so a closed stderr is handled the same way.

Version

hyperfine 1.20.0 (master @ f12f3d9)


This issue report was prepared with AI assistance; the bug itself was verified by reproduction on Linux and Windows.