diff --git a/src/body/body.rs b/src/body/body.rs index 699398b86f..111867a5ed 100644 --- a/src/body/body.rs +++ b/src/body/body.rs @@ -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)); } } diff --git a/src/proto/h1/dispatch.rs b/src/proto/h1/dispatch.rs index f96e63df4a..fddf639d9e 100644 --- a/src/proto/h1/dispatch.rs +++ b/src/proto/h1/dispatch.rs @@ -118,6 +118,10 @@ where should_shutdown: bool, ) -> Poll> { 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