@@ -9,7 +9,6 @@ const events = require('./events');
99const Server = require ( './server' ) . Server ;
1010const relayEvents = require ( '../utils' ) . relayEvents ;
1111const ReadPreference = require ( '../topologies/read_preference' ) ;
12- const isRetryableWritesSupported = require ( '../topologies/shared' ) . isRetryableWritesSupported ;
1312const CoreCursor = require ( '../cursor' ) . CoreCursor ;
1413const deprecate = require ( 'util' ) . deprecate ;
1514const BSON = require ( '../connection/utils' ) . retrieveBSON ( ) ;
@@ -669,12 +668,17 @@ class Topology extends EventEmitter {
669668 return ;
670669 }
671670
671+ const notAlreadyRetrying = ! options . retrying ;
672+ const retryWrites = ! ! options . retryWrites ;
673+ const hasSession = ! ! options . session ;
674+ const supportsRetryableWrites = server . supportsRetryableWrites ;
675+ const notInTransaction = ! hasSession || ! options . session . inTransaction ( ) ;
672676 const willRetryWrite =
673- ! options . retrying &&
674- ! ! options . retryWrites &&
675- options . session &&
676- isRetryableWritesSupported ( this ) &&
677- ! options . session . inTransaction ( ) &&
677+ notAlreadyRetrying &&
678+ retryWrites &&
679+ hasSession &&
680+ supportsRetryableWrites &&
681+ notInTransaction &&
678682 isWriteCommand ( cmd ) ;
679683
680684 const cb = ( err , result ) => {
@@ -925,20 +929,26 @@ function executeWriteOperation(args, options, callback) {
925929 const ns = args . ns ;
926930 const ops = args . ops ;
927931
928- const willRetryWrite =
929- ! args . retrying &&
930- ! ! options . retryWrites &&
931- options . session &&
932- isRetryableWritesSupported ( topology ) &&
933- ! options . session . inTransaction ( ) &&
934- options . explain === undefined ;
935-
936932 topology . selectServer ( writableServerSelector ( ) , options , ( err , server ) => {
937933 if ( err ) {
938934 callback ( err , null ) ;
939935 return ;
940936 }
941937
938+ const notAlreadyRetrying = ! args . retrying ;
939+ const retryWrites = ! ! options . retryWrites ;
940+ const hasSession = ! ! options . session ;
941+ const supportsRetryableWrites = server . supportsRetryableWrites ;
942+ const notInTransaction = ! hasSession || ! options . session . inTransaction ( ) ;
943+ const notExplaining = options . explain === undefined ;
944+ const willRetryWrite =
945+ notAlreadyRetrying &&
946+ retryWrites &&
947+ hasSession &&
948+ supportsRetryableWrites &&
949+ notInTransaction &&
950+ notExplaining ;
951+
942952 const handler = ( err , result ) => {
943953 if ( ! err ) return callback ( null , result ) ;
944954 if ( ! shouldRetryOperation ( err ) ) {
0 commit comments