@@ -300,10 +300,19 @@ function endTransaction(session, commandName, callback) {
300300 const command = { [ commandName ] : 1 } ;
301301
302302 // apply a writeConcern if specified
303+ let writeConcern ;
303304 if ( session . transaction . options . writeConcern ) {
304- Object . assign ( command , { writeConcern : session . transaction . options . writeConcern } ) ;
305+ writeConcern = Object . assign ( { } , session . transaction . options . writeConcern ) ;
305306 } else if ( session . clientOptions && session . clientOptions . w ) {
306- Object . assign ( command , { writeConcern : { w : session . clientOptions . w } } ) ;
307+ writeConcern = { w : session . clientOptions . w } ;
308+ }
309+
310+ if ( txnState === TxnState . TRANSACTION_COMMITTED ) {
311+ writeConcern = Object . assign ( { wtimeout : 10000 } , writeConcern , { w : 'majority' } ) ;
312+ }
313+
314+ if ( writeConcern ) {
315+ Object . assign ( command , { writeConcern } ) ;
307316 }
308317
309318 function commandHandler ( e , r ) {
@@ -342,6 +351,13 @@ function endTransaction(session, commandName, callback) {
342351 // send the command
343352 session . topology . command ( 'admin.$cmd' , command , { session } , ( err , reply ) => {
344353 if ( err && isRetryableError ( err ) ) {
354+ // SPEC-1185: apply majority write concern when retrying commitTransaction
355+ if ( command . commitTransaction ) {
356+ command . writeConcern = Object . assign ( { wtimeout : 10000 } , command . writeConcern , {
357+ w : 'majority'
358+ } ) ;
359+ }
360+
345361 return session . topology . command ( 'admin.$cmd' , command , { session } , ( _err , _reply ) =>
346362 commandHandler ( transactionError ( _err ) , _reply )
347363 ) ;
0 commit comments