set default max_lifetime in pool::Options to 30 minutes and explain why

This commit is contained in:
Austin Bonander 2019-12-19 19:06:58 -08:00 committed by Ryan Leckey
parent 786deecc36
commit 892a179787
2 changed files with 12 additions and 1 deletions

View File

@ -2,6 +2,14 @@ use std::collections::hash_map::{HashMap, Entry};
use std::cmp::Ordering;
use futures_core::Future;
// TODO: figure out a cache eviction strategy
// we currently naively cache all prepared statements which could live-leak memory
// on both the client and server if the user is synthesizing queries that are different each time
// We put an upper bound on this by setting a default max connection lifetime in pool::Options but
// that's only a band-aid
/// Per-connection prepared statement cache.
pub struct StatementCache<Id> {
statements: HashMap<String, Id>
}

View File

@ -68,7 +68,10 @@ impl Default for Options {
max_size: 10,
min_idle: 0,
connect_timeout: Duration::from_secs(30),
max_lifetime: None,
// 30 minutes
// prevents unbounded live-leaking of memory due to naive prepared statement caching
// see src/cache.rs for context
max_lifetime: Some(Duration::from_secs(1800)),
idle_timeout: None,
}
}