@@ -788,22 +788,11 @@ export class ClientSession
788788 await this . commitTransaction ( ) ;
789789 committed = true ;
790790 } catch ( commitError ) {
791+ // If CSOT is enabled, we repeatedly retry until timeoutMS expires.
792+ // If CSOT is not enabled, do we still have time remaining or have we timed out?
791793 const hasNotTimedOut =
792794 this . timeoutContext ?. csotEnabled ( ) || now ( ) - startTime < MAX_TIMEOUT ;
793795
794- /**
795- * will the provided backoffMS exceed the withTransaction's deadline?
796- */
797- const willExceedTransactionDeadline = ( backoffMS : number ) => {
798- return (
799- ( this . timeoutContext ?. csotEnabled ( ) &&
800- backoffMS > this . timeoutContext . remainingTimeMS ) ||
801- now ( ) + backoffMS > startTime + MAX_TIMEOUT
802- ) ;
803- } ;
804-
805- // If CSOT is enabled, we repeatedly retry until timeoutMS expires.
806- // If CSOT is not enabled, do we still have time remaining or have we timed out?
807796 if ( hasNotTimedOut ) {
808797 if (
809798 ! isMaxTimeMSExpiredError ( commitError ) &&
@@ -826,7 +815,12 @@ export class ClientSession
826815 const backoffMS =
827816 jitter * Math . min ( BACKOFF_INITIAL_MS * 1.5 ** retry , BACKOFF_MAX_MS ) ;
828817
829- if ( willExceedTransactionDeadline ( backoffMS ) ) {
818+ const willExceedTransactionDeadline =
819+ ( this . timeoutContext ?. csotEnabled ( ) &&
820+ backoffMS > this . timeoutContext . remainingTimeMS ) ||
821+ now ( ) + backoffMS > startTime + MAX_TIMEOUT ;
822+
823+ if ( willExceedTransactionDeadline ) {
830824 break ;
831825 }
832826
@@ -841,6 +835,7 @@ export class ClientSession
841835 }
842836 }
843837
838+ // @ts -expect-error Result is always defined if we reach here, the for-loop above convinces TS it is not.
844839 return result ;
845840 } finally {
846841 this . timeoutContext = null ;
0 commit comments