From 2f21783356100848f9756d6a3c6997be47bf08a9 Mon Sep 17 00:00:00 2001 From: Uzair Aftab Date: Tue, 17 Nov 2026 19:34:38 +0100 Subject: [PATCH] db: keep warm connections for ten minutes The pool closed any connection idle for 60 seconds. sqlx applies that to the minimum connections too, then reconnects at once to restore the minimum, so an idle service kept replacing its warm connections every minute. In production the replica pool, used only by reporting reads, opened five connections a minute around the clock. Raise the idle timeout to ten minutes. Connections opened for a burst are still returned afterwards, and the warm ones are replaced at most once per period rather than once a minute. --- workers/server/src/config.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/workers/server/src/config.rs b/workers/server/src/config.rs index bddea05..6404251 100644 --- a/workers/server/src/config.rs +++ b/workers/server/src/config.rs @@ -279,7 +279,11 @@ pub async fn connect_pool( Ok(true) }) }) - .idle_timeout(Duration::from_secs(60)); + // sqlx closes every connection idle past this, the minimum included, + // and then reconnects to restore the minimum. A short timeout therefore + // costs a TLS handshake and login per warm connection per period while + // nothing is happening. Ten minutes still returns burst capacity. + .idle_timeout(Duration::from_secs(600)); #[cfg(feature = "observability")] let options = if crate::observability::enabled() { options.acquire_time_level(log::LevelFilter::Debug)