Skip to content

Commit

Permalink
fix(client): prevent panicking when determine Expiration in pool
Browse files Browse the repository at this point in the history
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
  • Loading branch information
seanmonstar committed Jun 13, 2017
1 parent 620e00c commit c166268
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/client/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down

0 comments on commit c166268

Please sign in to comment.