diff --git a/CHANGELOG.md b/CHANGELOG.md index dc39fc7c..d32c6074 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Fixed * CI: Use Powershell Compress-Archive to create Windows binary zip #424 - @cyqsimon +* Exit gracefully when there is a broken pipe error #429 - @sigmaSd ## [0.23.0] - 2024-08-17 diff --git a/src/os/shared.rs b/src/os/shared.rs index bb0e532a..e1fbcdba 100644 --- a/src/os/shared.rs +++ b/src/os/shared.rs @@ -83,8 +83,14 @@ fn get_interface(interface_name: &str) -> Option { fn create_write_to_stdout() -> Box { let mut stdout = io::stdout(); Box::new({ - move |output: String| { - writeln!(stdout, "{}", output).unwrap(); + move |output: String| match writeln!(stdout, "{}", output) { + Ok(_) => (), + Err(e) if e.kind() == ErrorKind::BrokenPipe => { + // A process that was listening to bandwhich stdout has exited + // We can't do much here, lets just exit as well + std::process::exit(0) + } + Err(e) => panic!("Failed to write to stdout: {e}"), } }) }