From c166268c07df3c8073fa628ee24d09a10f90eceb Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Tue, 13 Jun 2017 09:21:56 -0700 Subject: [PATCH] fix(client): prevent panicking when determine Expiration in pool On some OSes, `Instant` would start counting 0 from the boot time. That would mean that any `Instant::now() - dur` soon after boot had a higher risk of overflowing. Now, the expiration is determined by calling `idle.elapsed()`, and comparing durations. Closes #1215 --- src/client/pool.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/pool.rs b/src/client/pool.rs index 32df227f..042ac03e 100644 --- a/src/client/pool.rs +++ b/src/client/pool.rs @@ -260,16 +260,16 @@ impl Future for Checkout { } } -struct Expiration(Option); +struct Expiration(Option); impl Expiration { fn new(dur: Option) -> Expiration { - Expiration(dur.map(|dur| Instant::now() - dur)) + Expiration(dur) } fn expires(&self, instant: Instant) -> bool { match self.0 { - Some(expire) => expire > instant, + Some(timeout) => instant.elapsed() > timeout, None => false, } }