summaryrefslogtreecommitdiffstats
path: root/tokio/src/time
diff options
context:
space:
mode:
authorChristofer Nolander <christofer.nolander@gmail.com>2020-03-26 20:54:56 +0100
committerGitHub <noreply@github.com>2020-03-26 12:54:56 -0700
commit6cf1a5b6b8686e5bde107d072d77199aaefcb2ec (patch)
tree97913775b60e5d19b7f0d5d18de0d1d01221435f /tokio/src/time
parent1cb1e291c10adf6b4e530cb1475b95ba10fa615f (diff)
time: fix DelayQueue rewriting delay on insert after Poll::Ready (#2285)
When the queue was polled and yielded an index from the wheel, the delay until the next item was never updated. As a result, when one item was yielded from `poll_idx` the following insert erronously updated the delay to the instant of the inserted item. Fixes: #1700
Diffstat (limited to 'tokio/src/time')
-rw-r--r--tokio/src/time/delay_queue.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/tokio/src/time/delay_queue.rs b/tokio/src/time/delay_queue.rs
index 1790ada8..821c0c27 100644
--- a/tokio/src/time/delay_queue.rs
+++ b/tokio/src/time/delay_queue.rs
@@ -721,15 +721,16 @@ impl<T> DelayQueue<T> {
self.poll = wheel::Poll::new(now);
}
- self.delay = None;
+ // We poll the wheel to get the next value out before finding the next deadline.
+ let wheel_idx = self.wheel.poll(&mut self.poll, &mut self.slab);
- if let Some(idx) = self.wheel.poll(&mut self.poll, &mut self.slab) {
+ self.delay = self.next_deadline().map(delay_until);
+
+ if let Some(idx) = wheel_idx {
return Poll::Ready(Some(Ok(idx)));
}
- if let Some(deadline) = self.next_deadline() {
- self.delay = Some(delay_until(deadline));
- } else {
+ if self.delay.is_none() {
return Poll::Ready(None);
}
}