@@ -150,16 +150,17 @@ function executeWithServerSelection(topology: Topology, operation: any, callback
150
150
return callback ( undefined , result ) ;
151
151
}
152
152
153
- if (
154
- ( operation . hasAspect ( Aspect . READ_OPERATION ) && ! isRetryableError ( err ) ) ||
155
- ( operation . hasAspect ( Aspect . WRITE_OPERATION ) && ! shouldRetryWrite ( err ) )
156
- ) {
153
+ const hasReadAspect = operation . hasAspect ( Aspect . READ_OPERATION ) ;
154
+ const hasWriteAspect = operation . hasAspect ( Aspect . WRITE_OPERATION ) ;
155
+ const itShouldRetryWrite = shouldRetryWrite ( err ) ;
156
+
157
+ if ( ( hasReadAspect && ! isRetryableError ( err ) ) || ( hasWriteAspect && ! itShouldRetryWrite ) ) {
157
158
return callback ( err ) ;
158
159
}
159
160
160
161
if (
161
- operation . hasAspect ( Aspect . WRITE_OPERATION ) &&
162
- shouldRetryWrite ( err ) &&
162
+ hasWriteAspect &&
163
+ itShouldRetryWrite &&
163
164
err . code === MMAPv1_RETRY_WRITES_ERROR_CODE &&
164
165
err . errmsg . match ( / T r a n s a c t i o n n u m b e r s / )
165
166
) {
@@ -196,32 +197,33 @@ function executeWithServerSelection(topology: Topology, operation: any, callback
196
197
return ;
197
198
}
198
199
199
- const willRetryRead =
200
- topology . s . options . retryReads !== false &&
201
- session &&
202
- ! inTransaction &&
203
- supportsRetryableReads ( server ) &&
204
- operation . canRetryRead ;
205
-
206
- const willRetryWrite =
207
- topology . s . options . retryWrites === true &&
208
- session &&
209
- ! inTransaction &&
210
- supportsRetryableWrites ( server ) &&
211
- operation . canRetryWrite ;
200
+ if ( operation . hasAspect ( Aspect . RETRYABLE ) ) {
201
+ const willRetryRead =
202
+ topology . s . options . retryReads !== false &&
203
+ operation . session &&
204
+ ! inTransaction &&
205
+ supportsRetryableReads ( server ) &&
206
+ operation . canRetryRead ;
207
+
208
+ const willRetryWrite =
209
+ topology . s . options . retryWrites === true &&
210
+ operation . session &&
211
+ ! inTransaction &&
212
+ supportsRetryableWrites ( server ) &&
213
+ operation . canRetryWrite ;
214
+
215
+ const hasReadAspect = operation . hasAspect ( Aspect . READ_OPERATION ) ;
216
+ const hasWriteAspect = operation . hasAspect ( Aspect . WRITE_OPERATION ) ;
217
+
218
+ if ( ( hasReadAspect && willRetryRead ) || ( hasWriteAspect && willRetryWrite ) ) {
219
+ if ( hasWriteAspect && willRetryWrite ) {
220
+ operation . options . willRetryWrite = true ;
221
+ operation . session . incrementTransactionNumber ( ) ;
222
+ }
212
223
213
- if (
214
- operation . hasAspect ( Aspect . RETRYABLE ) &&
215
- ( ( operation . hasAspect ( Aspect . READ_OPERATION ) && willRetryRead ) ||
216
- ( operation . hasAspect ( Aspect . WRITE_OPERATION ) && willRetryWrite ) )
217
- ) {
218
- if ( operation . hasAspect ( Aspect . WRITE_OPERATION ) && willRetryWrite ) {
219
- operation . options . willRetryWrite = true ;
220
- session . incrementTransactionNumber ( ) ;
224
+ operation . execute ( server , callbackWithRetry ) ;
225
+ return ;
221
226
}
222
-
223
- operation . execute ( server , callbackWithRetry ) ;
224
- return ;
225
227
}
226
228
227
229
operation . execute ( server , callback ) ;
0 commit comments