From bcf1724a055df662b6871b6ec62c20b31c8c0501 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Thu, 12 May 2022 16:04:26 +0200 Subject: [PATCH] Add a message for EOF-related broken pipe errors It's quite confusing from production logs when all I get is "broken pipe" and I don't know which path was taken for that error to be logged. --- src/proto/streams/state.rs | 8 +++++++- src/proto/streams/streams.rs | 8 +++++++- tests/h2-tests/tests/client_request.rs | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/proto/streams/state.rs b/src/proto/streams/state.rs index 1233e235..b876ffce 100644 --- a/src/proto/streams/state.rs +++ b/src/proto/streams/state.rs @@ -303,7 +303,13 @@ impl State { Closed(..) => {} ref state => { tracing::trace!("recv_eof; state={:?}", state); - self.inner = Closed(Cause::Error(io::ErrorKind::BrokenPipe.into())); + self.inner = Closed(Cause::Error( + io::Error::new( + io::ErrorKind::BrokenPipe, + "stream closed because of broken pipe", + ) + .into(), + )); } } } diff --git a/src/proto/streams/streams.rs b/src/proto/streams/streams.rs index 01bdcdd7..32addab0 100644 --- a/src/proto/streams/streams.rs +++ b/src/proto/streams/streams.rs @@ -806,7 +806,13 @@ impl Inner { let send_buffer = &mut *send_buffer; if actions.conn_error.is_none() { - actions.conn_error = Some(io::Error::from(io::ErrorKind::BrokenPipe).into()); + actions.conn_error = Some( + io::Error::new( + io::ErrorKind::BrokenPipe, + "connection closed because of broken pipe", + ) + .into(), + ); } tracing::trace!("Streams::recv_eof"); diff --git a/tests/h2-tests/tests/client_request.rs b/tests/h2-tests/tests/client_request.rs index 07b291f4..f4243a16 100644 --- a/tests/h2-tests/tests/client_request.rs +++ b/tests/h2-tests/tests/client_request.rs @@ -574,7 +574,7 @@ async fn connection_close_notifies_response_future() { .0 .await; let err = res.expect_err("response"); - assert_eq!(err.to_string(), "broken pipe"); + assert_eq!(err.to_string(), "stream closed because of broken pipe"); }; join(async move { conn.await.expect("conn") }, req).await; }; @@ -613,7 +613,7 @@ async fn connection_close_notifies_client_poll_ready() { .0 .await; let err = res.expect_err("response"); - assert_eq!(err.to_string(), "broken pipe"); + assert_eq!(err.to_string(), "stream closed because of broken pipe"); }; conn.drive(req).await;