mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-11-03 06:52:48 +00:00
set default max_lifetime in pool::Options to 30 minutes and explain why
This commit is contained in:
parent
786deecc36
commit
892a179787
@ -2,6 +2,14 @@ use std::collections::hash_map::{HashMap, Entry};
|
|||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use futures_core::Future;
|
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> {
|
pub struct StatementCache<Id> {
|
||||||
statements: HashMap<String, Id>
|
statements: HashMap<String, Id>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,7 +68,10 @@ impl Default for Options {
|
|||||||
max_size: 10,
|
max_size: 10,
|
||||||
min_idle: 0,
|
min_idle: 0,
|
||||||
connect_timeout: Duration::from_secs(30),
|
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,
|
idle_timeout: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user