Skip to content

Commit 24714a3

Browse files
authored
fix(client): cap pool idle interval to a minimum (#217)
1 parent f0dcda3 commit 24714a3

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/client/legacy/pool.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,14 @@ impl<T: Poolable, K: Key> PoolInner<T, K> {
433433
} else {
434434
return;
435435
};
436+
437+
// While someone might want a shorter duration, and it will be respected
438+
// at checkout time, there's no need to wake up and proactively evict
439+
// faster than this.
440+
const MIN_CHECK: Duration = Duration::from_millis(90);
441+
442+
let dur = dur.max(MIN_CHECK);
443+
436444
let (tx, rx) = oneshot::channel();
437445
self.idle_interval_ref = Some(tx);
438446

@@ -991,8 +999,15 @@ mod tests {
991999

9921000
// Let the timer tick passed the expiration...
9931001
tokio::time::sleep(Duration::from_millis(30)).await;
994-
// Yield so the Interval can reap...
995-
tokio::task::yield_now().await;
1002+
1003+
// But minimum interval is higher, so nothing should have been reaped
1004+
assert_eq!(
1005+
pool.locked().idle.get(&key).map(|entries| entries.len()),
1006+
Some(3)
1007+
);
1008+
1009+
// Now wait passed the minimum interval more
1010+
tokio::time::sleep(Duration::from_millis(70)).await;
9961011

9971012
assert!(!pool.locked().idle.contains_key(&key));
9981013
}

0 commit comments

Comments
 (0)