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
This commit is contained in:
Sean McArthur
2017-06-13 09:21:56 -07:00
parent 620e00c6da
commit c166268c07

View File

@@ -260,16 +260,16 @@ impl<T: Clone> Future for Checkout<T> {
}
}
struct Expiration(Option<Instant>);
struct Expiration(Option<Duration>);
impl Expiration {
fn new(dur: Option<Duration>) -> 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,
}
}