Skip to content

Commit dcdd6d1

Browse files
authored
fix(client): avoid panics in uses of Instant (#2746)
Even though this is almost definitely a bug in Rust, it seems most prudent to actively avoid the uses of `Instant` that are prone to this bug. This change replaces uses of `Instant::elapsed` and `Instant::sub` with calls to `Instant::saturating_duration_since` to prevent this class of panic.
1 parent f1b89c1 commit dcdd6d1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/client/pool.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,9 @@ impl<T: Poolable> PoolInner<T> {
458458
trace!("idle interval evicting closed for {:?}", key);
459459
return false;
460460
}
461-
if now - entry.idle_at > dur {
461+
462+
// Avoid `Instant::sub` to avoid issues like rust-lang/rust#86470.
463+
if now.saturating_duration_since(entry.idle_at) > dur {
462464
trace!("idle interval evicting expired for {:?}", key);
463465
return false;
464466
}
@@ -721,7 +723,8 @@ impl Expiration {
721723

722724
fn expires(&self, instant: Instant) -> bool {
723725
match self.0 {
724-
Some(timeout) => instant.elapsed() > timeout,
726+
// Avoid `Instant::elapsed` to avoid issues like rust-lang/rust#86470.
727+
Some(timeout) => Instant::now().saturating_duration_since(instant) > timeout,
725728
None => false,
726729
}
727730
}

0 commit comments

Comments
 (0)