@@ -482,13 +482,28 @@ export class ClientSession
482482 maxTimeMS ?: number ;
483483 } = { commitTransaction : 1 } ;
484484
485+ const timeoutMS =
486+ typeof options ?. timeoutMS === 'number'
487+ ? options . timeoutMS
488+ : typeof this . timeoutMS === 'number'
489+ ? this . timeoutMS
490+ : null ;
491+
485492 const wc = this . transaction . options . writeConcern ?? this . clientOptions ?. writeConcern ;
486493 if ( wc != null ) {
487- WriteConcern . apply ( command , { wtimeoutMS : 10000 , w : 'majority' , ...wc } ) ;
494+ if ( timeoutMS == null && this . timeoutContext == null ) {
495+ WriteConcern . apply ( command , { wtimeoutMS : 10000 , w : 'majority' , ...wc } ) ;
496+ } else {
497+ WriteConcern . apply ( command , { w : 'majority' , ...wc , wtimeoutMS : undefined } ) ;
498+ }
488499 }
489500
490501 if ( this . transaction . state === TxnState . TRANSACTION_COMMITTED ) {
491- WriteConcern . apply ( command , { wtimeoutMS : 10000 , ...wc , w : 'majority' } ) ;
502+ if ( timeoutMS == null && this . timeoutContext == null ) {
503+ WriteConcern . apply ( command , { wtimeoutMS : 10000 , ...wc , w : 'majority' } ) ;
504+ } else {
505+ WriteConcern . apply ( command , { w : 'majority' , ...wc , wtimeoutMS : undefined } ) ;
506+ }
492507 }
493508
494509 if ( typeof this . transaction . options . maxTimeMS === 'number' ) {
@@ -505,13 +520,6 @@ export class ClientSession
505520 bypassPinningCheck : true
506521 } ) ;
507522
508- const timeoutMS =
509- typeof options ?. timeoutMS === 'number'
510- ? options . timeoutMS
511- : typeof this . timeoutMS === 'number'
512- ? this . timeoutMS
513- : null ;
514-
515523 const timeoutContext =
516524 this . timeoutContext ??
517525 ( typeof timeoutMS === 'number'
@@ -601,21 +609,6 @@ export class ClientSession
601609 recoveryToken ?: Document ;
602610 } = { abortTransaction : 1 } ;
603611
604- const wc = this . transaction . options . writeConcern ?? this . clientOptions ?. writeConcern ;
605- if ( wc != null ) {
606- WriteConcern . apply ( command , { wtimeoutMS : 10000 , w : 'majority' , ...wc } ) ;
607- }
608-
609- if ( this . transaction . recoveryToken ) {
610- command . recoveryToken = this . transaction . recoveryToken ;
611- }
612-
613- const operation = new RunAdminCommandOperation ( command , {
614- session : this ,
615- readPreference : ReadPreference . primary ,
616- bypassPinningCheck : true
617- } ) ;
618-
619612 const timeoutMS =
620613 typeof options ?. timeoutMS === 'number'
621614 ? options . timeoutMS
@@ -634,6 +627,21 @@ export class ClientSession
634627 } )
635628 : null ;
636629
630+ const wc = this . transaction . options . writeConcern ?? this . clientOptions ?. writeConcern ;
631+ if ( wc != null && timeoutMS == null ) {
632+ WriteConcern . apply ( command , { wtimeoutMS : 10000 , w : 'majority' , ...wc } ) ;
633+ }
634+
635+ if ( this . transaction . recoveryToken ) {
636+ command . recoveryToken = this . transaction . recoveryToken ;
637+ }
638+
639+ const operation = new RunAdminCommandOperation ( command , {
640+ session : this ,
641+ readPreference : ReadPreference . primary ,
642+ bypassPinningCheck : true
643+ } ) ;
644+
637645 try {
638646 await executeOperation ( this . client , operation , timeoutContext ) ;
639647 this . unpin ( ) ;
0 commit comments