@@ -158,7 +158,7 @@ impl Client {
158158 . execute_operation_with_details ( op. borrow_mut ( ) , None )
159159 . await ?;
160160 let pinned =
161- self . pin_connection_for_cursor ( & details. output , & mut details. connection ) ?;
161+ self . pin_connection_for_cursor ( & details. output , & mut details. connection , None ) ?;
162162 Ok ( Cursor :: new (
163163 self . clone ( ) ,
164164 details. output ,
@@ -181,8 +181,11 @@ impl Client {
181181 . execute_operation_with_details ( op. borrow_mut ( ) , & mut * session)
182182 . await ?;
183183
184- let pinned =
185- self . pin_connection_for_session ( & details. output , & mut details. connection , session) ?;
184+ let pinned = self . pin_connection_for_cursor (
185+ & details. output ,
186+ & mut details. connection ,
187+ Some ( session) ,
188+ ) ?;
186189 Ok ( SessionCursor :: new ( self . clone ( ) , details. output , pinned) )
187190 }
188191
@@ -194,25 +197,16 @@ impl Client {
194197 & self ,
195198 spec : & CursorSpecification ,
196199 conn : & mut PooledConnection ,
200+ session : Option < & mut ClientSession > ,
197201 ) -> Result < Option < PinnedConnectionHandle > > {
198- if self . is_load_balanced ( ) && spec. info . id != 0 {
199- Ok ( Some ( conn. pin ( ) ?) )
200- } else {
201- Ok ( None )
202- }
203- }
204-
205- fn pin_connection_for_session (
206- & self ,
207- spec : & CursorSpecification ,
208- conn : & mut PooledConnection ,
209- session : & mut ClientSession ,
210- ) -> Result < Option < PinnedConnectionHandle > > {
211- if let Some ( handle) = session. transaction . pinned_connection ( ) {
202+ if let Some ( handle) = session. and_then ( |s| s. transaction . pinned_connection ( ) ) {
212203 // Cursor operations on a transaction share the same pinned connection.
213204 Ok ( Some ( handle. replicate ( ) ) )
205+ } else if self . is_load_balanced ( ) && spec. info . id != 0 {
206+ // Cursor operations on load balanced topologies always pin connections.
207+ Ok ( Some ( conn. pin ( ) ?) )
214208 } else {
215- self . pin_connection_for_cursor ( spec , conn )
209+ Ok ( None )
216210 }
217211 }
218212
@@ -245,7 +239,8 @@ impl Client {
245239 details. implicit_session = Some ( session) ;
246240 }
247241 let ( cursor_spec, cs_data) = details. output ;
248- let pinned = self . pin_connection_for_cursor ( & cursor_spec, & mut details. connection ) ?;
242+ let pinned =
243+ self . pin_connection_for_cursor ( & cursor_spec, & mut details. connection , None ) ?;
249244 let cursor = Cursor :: new ( self . clone ( ) , cursor_spec, details. implicit_session , pinned) ;
250245
251246 Ok ( ChangeStream :: new ( cursor, args, cs_data) )
@@ -277,8 +272,11 @@ impl Client {
277272 . execute_operation_with_details ( & mut op, & mut * session)
278273 . await ?;
279274 let ( cursor_spec, cs_data) = details. output ;
280- let pinned =
281- self . pin_connection_for_session ( & cursor_spec, & mut details. connection , session) ?;
275+ let pinned = self . pin_connection_for_cursor (
276+ & cursor_spec,
277+ & mut details. connection ,
278+ Some ( session) ,
279+ ) ?;
282280 let cursor = SessionCursor :: new ( self . clone ( ) , cursor_spec, pinned) ;
283281
284282 Ok ( SessionChangeStream :: new ( cursor, args, cs_data) )
@@ -1063,6 +1061,7 @@ struct ExecutionDetails<T: Operation> {
10631061 implicit_session : Option < ClientSession > ,
10641062}
10651063
1064+ #[ derive( Debug ) ]
10661065struct ExecutionRetry {
10671066 prior_txn_number : Option < i64 > ,
10681067 first_error : Error ,
0 commit comments