@@ -332,16 +332,24 @@ impl Client {
332332 Ok ( c) => c,
333333 Err ( mut err) => {
334334 err. add_labels_and_update_pin ( None , & mut session, None ) ?;
335+ if err. is_read_retryable ( ) && self . inner . options . retry_writes != Some ( false ) {
336+ err. add_label ( RETRYABLE_WRITE_ERROR ) ;
337+ }
335338
336- if err. is_pool_cleared ( ) {
339+ let op_retry = match self . get_op_retryability ( & op, & session) {
340+ Retryability :: Read => err. is_read_retryable ( ) ,
341+ Retryability :: Write => err. is_write_retryable ( ) ,
342+ _ => false ,
343+ } ;
344+ if err. is_pool_cleared ( ) || op_retry {
337345 return self . execute_retry ( & mut op, & mut session, None , err) . await ;
338346 } else {
339347 return Err ( err) ;
340348 }
341349 }
342350 } ;
343351
344- let retryability = self . get_retryability ( & conn, & op, & session) . await ?;
352+ let retryability = self . get_retryability ( & conn, & op, & session) ?;
345353
346354 let txn_number = match session {
347355 Some ( ref mut session) => {
@@ -433,7 +441,7 @@ impl Client {
433441 Err ( _) => return Err ( first_error) ,
434442 } ;
435443
436- let retryability = self . get_retryability ( & conn, op, session) . await ?;
444+ let retryability = self . get_retryability ( & conn, op, session) ?;
437445 if retryability == Retryability :: None {
438446 return Err ( first_error) ;
439447 }
@@ -825,35 +833,49 @@ impl Client {
825833 }
826834
827835 /// Returns the retryability level for the execution of this operation.
828- async fn get_retryability < T : Operation > (
836+ fn get_op_retryability < T : Operation > (
829837 & self ,
830- conn : & Connection ,
831838 op : & T ,
832839 session : & Option < & mut ClientSession > ,
833- ) -> Result < Retryability > {
834- if ! session
840+ ) -> Retryability {
841+ if session
835842 . as_ref ( )
836843 . map ( |session| session. in_transaction ( ) )
837844 . unwrap_or ( false )
838845 {
839- match op. retryability ( ) {
840- Retryability :: Read if self . inner . options . retry_reads != Some ( false ) => {
841- return Ok ( Retryability :: Read ) ;
842- }
843- Retryability :: Write if conn. stream_description ( ) ?. supports_retryable_writes ( ) => {
844- // commitTransaction and abortTransaction should be retried regardless of the
845- // value for retry_writes set on the Client
846- if op. name ( ) == CommitTransaction :: NAME
847- || op. name ( ) == AbortTransaction :: NAME
848- || self . inner . options . retry_writes != Some ( false )
849- {
850- return Ok ( Retryability :: Write ) ;
851- }
852- }
853- _ => { }
846+ return Retryability :: None ;
847+ }
848+ match op. retryability ( ) {
849+ Retryability :: Read if self . inner . options . retry_reads != Some ( false ) => {
850+ Retryability :: Read
851+ }
852+ // commitTransaction and abortTransaction should be retried regardless of the
853+ // value for retry_writes set on the Client
854+ Retryability :: Write
855+ if op. name ( ) == CommitTransaction :: NAME
856+ || op. name ( ) == AbortTransaction :: NAME
857+ || self . inner . options . retry_writes != Some ( false ) =>
858+ {
859+ Retryability :: Write
860+ }
861+ _ => Retryability :: None ,
862+ }
863+ }
864+
865+ /// Returns the retryability level for the execution of this operation on this connection.
866+ fn get_retryability < T : Operation > (
867+ & self ,
868+ conn : & Connection ,
869+ op : & T ,
870+ session : & Option < & mut ClientSession > ,
871+ ) -> Result < Retryability > {
872+ match self . get_op_retryability ( op, session) {
873+ Retryability :: Read => Ok ( Retryability :: Read ) ,
874+ Retryability :: Write if conn. stream_description ( ) ?. supports_retryable_writes ( ) => {
875+ Ok ( Retryability :: Write )
854876 }
877+ _ => Ok ( Retryability :: None ) ,
855878 }
856- Ok ( Retryability :: None )
857879 }
858880
859881 async fn update_cluster_time (
0 commit comments