Skip to content

Commit

Permalink
fix(http1): send error on Incoming body when connection errors (#3256)
Browse files Browse the repository at this point in the history
If a connection has any error besides reading, a streaming body
sometimes wouldn't be notified. This change makes it so that when a
connection task is closing because of any error, an existing body
channel is also notified.

Closes #3253
  • Loading branch information
seanmonstar committed Jun 20, 2023
1 parent 32422c4 commit b107655
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/body/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,17 +602,16 @@ impl Sender {
}

/// Aborts the body in an abnormal fashion.
pub fn abort(self) {
pub fn abort(mut self) {
self.send_error(crate::Error::new_body_write_aborted());
}

pub(crate) fn send_error(&mut self, err: crate::Error) {
let _ = self
.data_tx
// clone so the send works even if buffer is full
.clone()
.try_send(Err(crate::Error::new_body_write_aborted()));
}

#[cfg(feature = "http1")]
pub(crate) fn send_error(&mut self, err: crate::Error) {
let _ = self.data_tx.try_send(Err(err));
.try_send(Err(err));
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/proto/h1/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ where
should_shutdown: bool,
) -> Poll<crate::Result<Dispatched>> {
Poll::Ready(ready!(self.poll_inner(cx, should_shutdown)).or_else(|e| {
// Be sure to alert a streaming body of the failure.
if let Some(mut body) = self.body_tx.take() {
body.send_error(crate::Error::new_body("connection error"));
}
// An error means we're shutting down either way.
// We just try to give the error to the user,
// and close the connection with an Ok. If we
Expand Down

0 comments on commit b107655

Please sign in to comment.