Skip to content

Commit 5ac3293

Browse files
authored
time: don't panic when Instant is not monotonic (#4044)
1 parent d0305d5 commit 5ac3293

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tokio/src/time/driver/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,21 @@ impl Handle {
288288
self.process_at_time(now)
289289
}
290290

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

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

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

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

0 commit comments

Comments
 (0)