Skip to content

Commit

Permalink
time: don't panic when Instant is not monotonic (#4044)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn committed Aug 19, 2021
1 parent d0305d5 commit 5ac3293
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tokio/src/time/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,21 @@ impl Handle {
self.process_at_time(now)
}

pub(self) fn process_at_time(&self, now: u64) {
pub(self) fn process_at_time(&self, mut now: u64) {
let mut waker_list: [Option<Waker>; 32] = Default::default();
let mut waker_idx = 0;

let mut lock = self.get().lock();

assert!(now >= lock.elapsed);
if now < lock.elapsed {
// Time went backwards! This normally shouldn't happen as the Rust language
// guarantees that an Instant is monotonic, but can happen when running
// Linux in a VM on a Windows host due to std incorrectly trusting the
// hardware clock to be monotonic.
//
// See <https://github.com/tokio-rs/tokio/issues/3619> for more information.
now = lock.elapsed;
}

while let Some(entry) = lock.wheel.poll(now) {
debug_assert!(unsafe { entry.is_pending() });
Expand Down

0 comments on commit 5ac3293

Please sign in to comment.