From f2ec01249aa92572e2c89e7696858c95f4fd0836 Mon Sep 17 00:00:00 2001 From: Jordan Mecom Date: Fri, 31 Jul 2026 14:55:20 -0700 Subject: [PATCH] Apply Postgres timeouts to replica reads Co-authored-by: Jordan Mecom Signed-off-by: Jordan Mecom --- crates/buzz-db/src/lib.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/buzz-db/src/lib.rs b/crates/buzz-db/src/lib.rs index 4b2010b869..99af5da1fe 100644 --- a/crates/buzz-db/src/lib.rs +++ b/crates/buzz-db/src/lib.rs @@ -749,6 +749,9 @@ impl Db { .acquire_timeout(Self::READER_ACQUIRE_TIMEOUT) .max_lifetime(Duration::from_secs(config.max_lifetime_secs)) .idle_timeout(Duration::from_secs(config.idle_timeout_secs)) + .after_connect(|connection, _meta| { + Box::pin(apply_runtime_connection_timeouts(connection)) + }) .connect_lazy(url)?) } @@ -8339,7 +8342,8 @@ mod tests { let idx = base.rfind('/').expect("db url has a path segment"); let scratch_url = format!("{}/{}", &base[..idx], name); let db = Db::new(&DbConfig { - database_url: scratch_url, + database_url: scratch_url.clone(), + read_database_url: Some(scratch_url), max_connections: 2, ..DbConfig::default() }) @@ -8359,6 +8363,18 @@ mod tests { assert_eq!(statement_timeout, RUNTIME_STATEMENT_TIMEOUT); assert_eq!(lock_timeout, RUNTIME_LOCK_TIMEOUT); + let read_pool = db.read_pool.as_ref().expect("read pool configured"); + let reader_statement_timeout: String = sqlx::query_scalar("SHOW statement_timeout") + .fetch_one(read_pool) + .await + .expect("SHOW reader statement_timeout"); + let reader_lock_timeout: String = sqlx::query_scalar("SHOW lock_timeout") + .fetch_one(read_pool) + .await + .expect("SHOW reader lock_timeout"); + assert_eq!(reader_statement_timeout, RUNTIME_STATEMENT_TIMEOUT); + assert_eq!(reader_lock_timeout, RUNTIME_LOCK_TIMEOUT); + let effective: String = sqlx::query_scalar("SHOW buzz.created_at_floor") .fetch_one(&db.pool) .await