Skip to content

Commit

Permalink
Guard Wheel.remove against expired instant removals
Browse files Browse the repository at this point in the history
Trying to remove an already expired Timer Wheel entry (called by
DelayQueue.reset()) in some cases as described in (tokio-rs#2573) causes panics.

This prevents this panic by omitting removal in these cases
  • Loading branch information
fegies committed Jun 5, 2020
1 parent ccf3dee commit 14ac9f1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tokio/src/time/wheel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ where
/// Remove `item` from thee timing wheel.
pub(crate) fn remove(&mut self, item: &T::Borrowed, store: &mut T::Store) {
let when = T::when(item, store);
let level = self.level_for(when);

self.levels[level].remove_entry(when, item, store);
if when > self.elapsed {
let level = self.level_for(when);
self.levels[level].remove_entry(when, item, store);
}
}

/// Instant at which to poll
Expand Down

0 comments on commit 14ac9f1

Please sign in to comment.