Skip to content

Commit 52f1925

Browse files
authoredJun 19, 2023
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 fec64cf commit 52f1925

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed
 

‎src/body/incoming.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,17 @@ impl Sender {
337337
.map_err(|err| err.into_inner().expect("just sent Ok"))
338338
}
339339

340-
/// Aborts the body in an abnormal fashion.
341340
#[allow(unused)]
342-
pub(crate) fn abort(self) {
341+
pub(crate) fn abort(mut self) {
342+
self.send_error(crate::Error::new_body_write_aborted());
343+
}
344+
345+
pub(crate) fn send_error(&mut self, err: crate::Error) {
343346
let _ = self
344347
.data_tx
345348
// clone so the send works even if buffer is full
346349
.clone()
347-
.try_send(Err(crate::Error::new_body_write_aborted()));
348-
}
349-
350-
#[cfg(feature = "http1")]
351-
pub(crate) fn send_error(&mut self, err: crate::Error) {
352-
let _ = self.data_tx.try_send(Err(err));
350+
.try_send(Err(err));
353351
}
354352
}
355353

‎src/proto/h1/dispatch.rs

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

0 commit comments

Comments
 (0)
Please sign in to comment.