@@ -570,11 +570,11 @@ async function attemptTransactionCommit<T>(
570
570
! isMaxTimeMSExpiredError ( err )
571
571
) {
572
572
if ( err . hasErrorLabel ( MongoErrorLabel . UnknownTransactionCommitResult ) ) {
573
- return attemptTransactionCommit ( session , startTime , fn , result , options ) ;
573
+ return await attemptTransactionCommit ( session , startTime , fn , result , options ) ;
574
574
}
575
575
576
576
if ( err . hasErrorLabel ( MongoErrorLabel . TransientTransactionError ) ) {
577
- return attemptTransaction ( session , startTime , fn , options ) ;
577
+ return await attemptTransaction ( session , startTime , fn , options ) ;
578
578
}
579
579
}
580
580
@@ -748,13 +748,28 @@ async function endTransaction(
748
748
command . recoveryToken = session . transaction . recoveryToken ;
749
749
}
750
750
751
- const handleFirstCommandAttempt = async ( error ?: Error ) => {
751
+ const partiallyHandleFirstCommandAttempt = async ( ) => {
752
752
if ( command . abortTransaction ) {
753
753
// always unpin on abort regardless of command outcome
754
754
session . unpin ( ) ;
755
755
}
756
+ } ;
756
757
757
- if ( error instanceof MongoError && isRetryableWriteError ( error ) ) {
758
+ try {
759
+ // send the command
760
+ await executeOperation (
761
+ session . client ,
762
+ new RunAdminCommandOperation ( command , {
763
+ session,
764
+ readPreference : ReadPreference . primary ,
765
+ bypassPinningCheck : true
766
+ } )
767
+ ) ;
768
+ await partiallyHandleFirstCommandAttempt ( ) ;
769
+ commandHandler ( ) ;
770
+ } catch ( err ) {
771
+ await partiallyHandleFirstCommandAttempt ( ) ;
772
+ if ( err instanceof MongoError && isRetryableWriteError ( err ) ) {
758
773
// SPEC-1185: apply majority write concern when retrying commitTransaction
759
774
if ( command . commitTransaction ) {
760
775
// per txns spec, must unpin session in this case
@@ -775,27 +790,12 @@ async function endTransaction(
775
790
} )
776
791
) ;
777
792
commandHandler ( ) ;
778
- } catch ( e ) {
779
- commandHandler ( e ) ;
793
+ } catch ( err2 ) {
794
+ commandHandler ( err2 ) ;
780
795
}
781
- return ;
796
+ } else {
797
+ commandHandler ( err ) ;
782
798
}
783
- commandHandler ( error ) ;
784
- } ;
785
-
786
- try {
787
- // send the command
788
- await executeOperation (
789
- session . client ,
790
- new RunAdminCommandOperation ( command , {
791
- session,
792
- readPreference : ReadPreference . primary ,
793
- bypassPinningCheck : true
794
- } )
795
- ) ;
796
- await handleFirstCommandAttempt ( ) ;
797
- } catch ( e ) {
798
- await handleFirstCommandAttempt ( e ) ;
799
799
}
800
800
}
801
801
0 commit comments