From 03c291f171ac6ed9fb4e69d83df8693643b6d40c Mon Sep 17 00:00:00 2001 From: Mostafa Date: Thu, 23 Jan 2025 20:32:48 -0600 Subject: [PATCH 1/3] Avoid holding on to pools after reload --- src/client.rs | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/client.rs b/src/client.rs index c226436e..77e74aa7 100644 --- a/src/client.rs +++ b/src/client.rs @@ -870,19 +870,6 @@ where &self.pool_name, ); - // Get a pool instance referenced by the most up-to-date - // pointer. This ensures we always read the latest config - // when starting a query. - let mut pool = if self.admin { - // Admin clients do not use pools. - ConnectionPool::default() - } else { - self.get_pool().await? - }; - - query_router.update_pool_settings(&pool.settings); - query_router.set_default_role(); - // Our custom protocol loop. // We expect the client to either start a transaction with regular queries // or issue commands for our sharding and server selection protocol. @@ -933,6 +920,19 @@ where continue; } + // Get a pool instance referenced by the most up-to-date + // pointer. This ensures we always read the latest config + // when starting a query. + let mut pool = if self.admin { + // Admin clients do not use pools. + ConnectionPool::default() + } else { + self.get_pool().await? + }; + + query_router.update_pool_settings(&pool.settings); + query_router.set_default_role(); + // Handle all custom protocol commands, if any. if self .handle_custom_protocol(&mut query_router, &message, &pool) @@ -1055,11 +1055,12 @@ where }; // Check if the pool is paused and wait until it's resumed. - pool.wait_paused().await; - - // Refresh pool information, something might have changed. - pool = self.get_pool().await?; - query_router.update_pool_settings(&pool.settings); + if pool.paused() { + pool.wait_paused().await; + // Refresh pool information, something might have changed. + pool = self.get_pool().await?; + query_router.update_pool_settings(&pool.settings); + } debug!("Waiting for connection from pool"); if !self.admin { From 527ecebaec9c7c6151b9f98a096e23d0b7392e8e Mon Sep 17 00:00:00 2001 From: Mostafa Date: Thu, 23 Jan 2025 21:09:38 -0600 Subject: [PATCH 2/3] fix tests --- src/client.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/client.rs b/src/client.rs index 77e74aa7..e486d888 100644 --- a/src/client.rs +++ b/src/client.rs @@ -858,6 +858,14 @@ where // The query router determines where the query is going to go, // e.g. primary, replica, which shard. let mut query_router = QueryRouter::new(); + let pool_settings = if self.admin { + // Admin clients do not use pools. + ConnectionPool::default().settings + } else { + self.get_pool().await?.settings + }; + query_router.update_pool_settings(&pool_settings); + query_router.set_default_role(); self.stats.register(self.stats.clone()); From ef811c422308a6ca8503162ca06abf59978f6a3c Mon Sep 17 00:00:00 2001 From: Mostafa Date: Thu, 23 Jan 2025 21:25:03 -0600 Subject: [PATCH 3/3] fix --- src/client.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client.rs b/src/client.rs index e486d888..77dcaab4 100644 --- a/src/client.rs +++ b/src/client.rs @@ -939,7 +939,6 @@ where }; query_router.update_pool_settings(&pool.settings); - query_router.set_default_role(); // Handle all custom protocol commands, if any. if self