Skip to content

Commit b107655

Browse files
committed
fix(http1): send error on Incoming body when connection errors (#3256)
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
1 parent 32422c4 commit b107655

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/body/body.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -602,17 +602,16 @@ impl Sender {
602602
}
603603

604604
/// Aborts the body in an abnormal fashion.
605-
pub fn abort(self) {
605+
pub fn abort(mut self) {
606+
self.send_error(crate::Error::new_body_write_aborted());
607+
}
608+
609+
pub(crate) fn send_error(&mut self, err: crate::Error) {
606610
let _ = self
607611
.data_tx
608612
// clone so the send works even if buffer is full
609613
.clone()
610-
.try_send(Err(crate::Error::new_body_write_aborted()));
611-
}
612-
613-
#[cfg(feature = "http1")]
614-
pub(crate) fn send_error(&mut self, err: crate::Error) {
615-
let _ = self.data_tx.try_send(Err(err));
614+
.try_send(Err(err));
616615
}
617616
}
618617

src/proto/h1/dispatch.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ where
118118
should_shutdown: bool,
119119
) -> Poll<crate::Result<Dispatched>> {
120120
Poll::Ready(ready!(self.poll_inner(cx, should_shutdown)).or_else(|e| {
121+
// Be sure to alert a streaming body of the failure.
122+
if let Some(mut body) = self.body_tx.take() {
123+
body.send_error(crate::Error::new_body("connection error"));
124+
}
121125
// An error means we're shutting down either way.
122126
// We just try to give the error to the user,
123127
// and close the connection with an Ok. If we

0 commit comments

Comments
 (0)