@@ -858,6 +858,14 @@ where
858858 // The query router determines where the query is going to go,
859859 // e.g. primary, replica, which shard.
860860 let mut query_router = QueryRouter :: new ( ) ;
861+ let pool_settings = if self . admin {
862+ // Admin clients do not use pools.
863+ ConnectionPool :: default ( ) . settings
864+ } else {
865+ self . get_pool ( ) . await ?. settings
866+ } ;
867+ query_router. update_pool_settings ( & pool_settings) ;
868+ query_router. set_default_role ( ) ;
861869
862870 self . stats . register ( self . stats . clone ( ) ) ;
863871
@@ -870,19 +878,6 @@ where
870878 & self . pool_name ,
871879 ) ;
872880
873- // Get a pool instance referenced by the most up-to-date
874- // pointer. This ensures we always read the latest config
875- // when starting a query.
876- let mut pool = if self . admin {
877- // Admin clients do not use pools.
878- ConnectionPool :: default ( )
879- } else {
880- self . get_pool ( ) . await ?
881- } ;
882-
883- query_router. update_pool_settings ( & pool. settings ) ;
884- query_router. set_default_role ( ) ;
885-
886881 // Our custom protocol loop.
887882 // We expect the client to either start a transaction with regular queries
888883 // or issue commands for our sharding and server selection protocol.
@@ -933,6 +928,18 @@ where
933928 continue ;
934929 }
935930
931+ // Get a pool instance referenced by the most up-to-date
932+ // pointer. This ensures we always read the latest config
933+ // when starting a query.
934+ let mut pool = if self . admin {
935+ // Admin clients do not use pools.
936+ ConnectionPool :: default ( )
937+ } else {
938+ self . get_pool ( ) . await ?
939+ } ;
940+
941+ query_router. update_pool_settings ( & pool. settings ) ;
942+
936943 // Handle all custom protocol commands, if any.
937944 if self
938945 . handle_custom_protocol ( & mut query_router, & message, & pool)
@@ -1055,11 +1062,12 @@ where
10551062 } ;
10561063
10571064 // Check if the pool is paused and wait until it's resumed.
1058- pool. wait_paused ( ) . await ;
1059-
1060- // Refresh pool information, something might have changed.
1061- pool = self . get_pool ( ) . await ?;
1062- query_router. update_pool_settings ( & pool. settings ) ;
1065+ if pool. paused ( ) {
1066+ pool. wait_paused ( ) . await ;
1067+ // Refresh pool information, something might have changed.
1068+ pool = self . get_pool ( ) . await ?;
1069+ query_router. update_pool_settings ( & pool. settings ) ;
1070+ }
10631071
10641072 debug ! ( "Waiting for connection from pool" ) ;
10651073 if !self . admin {
0 commit comments