From d5a32f45f694259d93f8a29bd4b4f6070f5ed6c6 Mon Sep 17 00:00:00 2001 From: Lev Kokotov Date: Tue, 6 Oct 2026 14:52:58 -0700 Subject: [PATCH] fix: failed primary stalls checkouts --- pgdog/src/backend/pool/lb/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pgdog/src/backend/pool/lb/mod.rs b/pgdog/src/backend/pool/lb/mod.rs index 819a068a8..09aa0bf05 100644 --- a/pgdog/src/backend/pool/lb/mod.rs +++ b/pgdog/src/backend/pool/lb/mod.rs @@ -352,7 +352,17 @@ impl LoadBalancer { /// replica-only configurations fail immediately with [`Error::NoPrimary`]. pub(super) async fn get_primary(&self, request: &Request) -> Result { if let Some(pool) = self.primary() { - return pool.get(request).await; + return tokio::select! { + guard = pool.get(request) => { + Ok(guard?) + } + + // Abort waiting for a connection from the primary + // if leader election takes place. + primary = self.wait_primary() => { + Ok(primary?.get(request).await?) + } + }; } if !self.role_detection_enabled() {