@@ -9,7 +9,6 @@ const events = require('./events');
9
9
const Server = require ( './server' ) . Server ;
10
10
const relayEvents = require ( '../utils' ) . relayEvents ;
11
11
const ReadPreference = require ( '../topologies/read_preference' ) ;
12
- const isRetryableWritesSupported = require ( '../topologies/shared' ) . isRetryableWritesSupported ;
13
12
const CoreCursor = require ( '../cursor' ) . CoreCursor ;
14
13
const deprecate = require ( 'util' ) . deprecate ;
15
14
const BSON = require ( '../connection/utils' ) . retrieveBSON ( ) ;
@@ -669,12 +668,17 @@ class Topology extends EventEmitter {
669
668
return ;
670
669
}
671
670
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 ( ) ;
672
676
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 &&
678
682
isWriteCommand ( cmd ) ;
679
683
680
684
const cb = ( err , result ) => {
@@ -925,20 +929,26 @@ function executeWriteOperation(args, options, callback) {
925
929
const ns = args . ns ;
926
930
const ops = args . ops ;
927
931
928
- const willRetryWrite =
929
- ! args . retrying &&
930
- ! ! options . retryWrites &&
931
- options . session &&
932
- isRetryableWritesSupported ( topology ) &&
933
- ! options . session . inTransaction ( ) &&
934
- options . explain === undefined ;
935
-
936
932
topology . selectServer ( writableServerSelector ( ) , options , ( err , server ) => {
937
933
if ( err ) {
938
934
callback ( err , null ) ;
939
935
return ;
940
936
}
941
937
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
+
942
952
const handler = ( err , result ) => {
943
953
if ( ! err ) return callback ( null , result ) ;
944
954
if ( ! shouldRetryOperation ( err ) ) {
0 commit comments