v0.33.8
This commit is contained in:
1 parent
6b937aaf85
commit
87c8393d86
79 files changed
+6727
-297
No files matched your search
+17
-7
@@ -18,7 +18,7 @@ use std::{
|
||||
};
|
||||
use tokio::{
|
||||
sync::OwnedSemaphorePermit,
|
||||
time::{sleep, Sleep},
|
||||
time::{sleep_until, Sleep},
|
||||
};
|
||||
|
||||
pub struct Exchange {
|
||||
@@ -263,7 +263,8 @@ pub struct MeteredBody {
|
||||
inner: Body,
|
||||
exchange: Option<Arc<Exchange>>,
|
||||
direction: Direction,
|
||||
timer: Pin<Box<Sleep>>,
|
||||
timer: Option<Pin<Box<Sleep>>>,
|
||||
deadline: tokio::time::Instant,
|
||||
idle: Duration,
|
||||
finished: bool,
|
||||
}
|
||||
@@ -274,13 +275,17 @@ impl MeteredBody {
|
||||
inner,
|
||||
exchange: Some(exchange),
|
||||
direction,
|
||||
timer: Box::pin(sleep(idle)),
|
||||
// Ready/empty bodies never need a timer allocation. Keep the
|
||||
// original deadline so a delayed first poll still times out.
|
||||
timer: None,
|
||||
deadline: tokio::time::Instant::now() + idle,
|
||||
idle,
|
||||
finished,
|
||||
}
|
||||
}
|
||||
fn finish(&mut self) {
|
||||
self.finished = true;
|
||||
self.timer.take();
|
||||
self.exchange.take();
|
||||
}
|
||||
}
|
||||
@@ -318,11 +323,13 @@ impl HttpBody for MeteredBody {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.timer
|
||||
.as_mut()
|
||||
.reset(tokio::time::Instant::now() + this.idle);
|
||||
if this.inner.is_end_stream() {
|
||||
this.finish();
|
||||
} else {
|
||||
this.deadline = tokio::time::Instant::now() + this.idle;
|
||||
if let Some(timer) = this.timer.as_mut() {
|
||||
timer.as_mut().reset(this.deadline);
|
||||
}
|
||||
}
|
||||
Poll::Ready(Some(Ok(frame)))
|
||||
}
|
||||
@@ -342,7 +349,10 @@ impl HttpBody for MeteredBody {
|
||||
Poll::Ready(None)
|
||||
}
|
||||
Poll::Pending => {
|
||||
if this.timer.as_mut().poll(cx).is_ready() {
|
||||
let timer = this
|
||||
.timer
|
||||
.get_or_insert_with(|| Box::pin(sleep_until(this.deadline)));
|
||||
if timer.as_mut().poll(cx).is_ready() {
|
||||
if let Some(exchange) = &this.exchange {
|
||||
exchange.failed.store(true, Ordering::Relaxed);
|
||||
exchange.backend_error(match this.direction {
|
||||
|
||||
Reference in new issue
Block a user