fix(http1): try to drain connection buffer if user drops Body

This commit is contained in:
Sean McArthur
2020-03-09 12:23:55 -07:00
parent 5b046a1f8f
commit d838d54fdf
3 changed files with 107 additions and 3 deletions

View File

@@ -655,6 +655,20 @@ where
}
}
/// If the read side can be cheaply drained, do so. Otherwise, close.
pub(super) fn poll_drain_or_close_read(&mut self, cx: &mut task::Context<'_>) {
let _ = self.poll_read_body(cx);
// If still in Reading::Body, just give up
match self.state.reading {
Reading::Init | Reading::KeepAlive => {
trace!("body drained");
return;
}
_ => self.close_read(),
}
}
pub fn close_read(&mut self) {
self.state.close_read();
}

View File

@@ -186,9 +186,9 @@ where
Poll::Ready(Err(_canceled)) => {
// user doesn't care about the body
// so we should stop reading
trace!("body receiver dropped before eof, closing");
self.conn.close_read();
return Poll::Ready(Ok(()));
trace!("body receiver dropped before eof, draining or closing");
self.conn.poll_drain_or_close_read(cx);
continue;
}
}
match self.conn.poll_read_body(cx) {