Skip to content

Commit

Permalink
Add a message for EOF-related broken pipe errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nox committed Feb 14, 2023
1 parent 73bea23 commit 0af2c67
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/proto/streams/state.rs
Expand Up @@ -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(),
));
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/proto/streams/streams.rs
Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions tests/h2-tests/tests/client_request.rs
Expand Up @@ -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;
};
Expand Down Expand Up @@ -613,15 +613,15 @@ 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;

let err = poll_fn(move |cx| client.poll_ready(cx))
.await
.expect_err("poll_ready");
assert_eq!(err.to_string(), "broken pipe");
assert_eq!(err.to_string(), "connection closed because of broken pipe");
};

join(srv, client).await;
Expand Down

0 comments on commit 0af2c67

Please sign in to comment.