From 5ac32934b409f9c77510e41b0f10abe5e855cde5 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Thu, 19 Aug 2021 09:41:35 +0200 Subject: [PATCH] time: don't panic when Instant is not monotonic (#4044) --- tokio/src/time/driver/mod.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tokio/src/time/driver/mod.rs b/tokio/src/time/driver/mod.rs index 37d2231c34f..f611fbb9c8e 100644 --- a/tokio/src/time/driver/mod.rs +++ b/tokio/src/time/driver/mod.rs @@ -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; 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 for more information. + now = lock.elapsed; + } while let Some(entry) = lock.wheel.poll(now) { debug_assert!(unsafe { entry.is_pending() });