Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pgdog/src/backend/pool/lb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,17 @@ impl LoadBalancer {
/// replica-only configurations fail immediately with [`Error::NoPrimary`].
pub(super) async fn get_primary(&self, request: &Request) -> Result<Guard, Error> {
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() {
Expand Down
Loading