Skip to content

Commit

Permalink
Add a message for EOF-related broken pipe errors (#615)
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 authored Feb 22, 2023
1 parent 7323190 commit 96caf4f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/proto/streams/state.rs
Original file line number Diff line number Diff line change
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 a broken pipe",
)
.into(),
));
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/proto/streams/streams.rs
Original file line number Diff line number Diff line change
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 a broken pipe",
)
.into(),
);
}

tracing::trace!("Streams::recv_eof");
Expand Down
9 changes: 6 additions & 3 deletions tests/h2-tests/tests/client_request.rs
Original file line number Diff line number Diff line change
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 a broken pipe");
};
join(async move { conn.await.expect("conn") }, req).await;
};
Expand Down Expand Up @@ -613,15 +613,18 @@ 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 a 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 a broken pipe"
);
};

join(srv, client).await;
Expand Down

0 comments on commit 96caf4f

Please sign in to comment.