@@ -76,7 +76,7 @@ public static TResult Execute<TResult>(OperationContext operationContext, IRetry
7676 {
7777 originalException ??= ex ;
7878
79- if ( ! ShouldRetry ( operationContext , operation . WriteConcern , context , server , tokenBucket , ex , attempt , context . Random , out var backoff ) )
79+ if ( ! ShouldRetry ( operationContext , operation . WriteConcern , context , tokenBucket , ex , attempt , context . Random , out var backoff ) )
8080 {
8181 throw originalException ;
8282 }
@@ -148,7 +148,7 @@ public static async Task<TResult> ExecuteAsync<TResult>(OperationContext operati
148148 {
149149 originalException ??= ex ;
150150
151- if ( ! ShouldRetry ( operationContext , operation . WriteConcern , context , server , tokenBucket , ex , attempt , context . Random , out var backoff ) )
151+ if ( ! ShouldRetry ( operationContext , operation . WriteConcern , context , tokenBucket , ex , attempt , context . Random , out var backoff ) )
152152 {
153153 throw originalException ;
154154 }
@@ -168,34 +168,28 @@ public static async Task<TResult> ExecuteAsync<TResult>(OperationContext operati
168168 private static bool ShouldRetry ( OperationContext operationContext ,
169169 WriteConcern writeConcern ,
170170 RetryableWriteContext context ,
171- ServerDescription server ,
172171 TokenBucket tokenBucket ,
173172 Exception exception ,
174173 int attempt ,
175174 IRandom random ,
176175 out TimeSpan backoff )
177176 {
178- var isAuthException = exception is MongoAuthenticationException ;
177+ backoff = TimeSpan . Zero ;
178+
179179 exception = exception is MongoAuthenticationException mongoAuthenticationException ? mongoAuthenticationException . InnerException : exception ;
180180
181- bool isRetryableReadOrWrite ;
182- if ( isAuthException )
183- {
184- //Auth operations are retried only according to retryable reads logic
185- var isRetryableReadException = RetryabilityHelper . IsRetryableReadException ( exception ) ;
186- isRetryableReadOrWrite = context . RetryRequested && ! context . Binding . Session . IsInTransaction && isRetryableReadException ;
187- }
188- else
189- {
190- var isRetryableWriteException = RetryabilityHelper . IsRetryableWriteException ( exception ) ;
191- isRetryableReadOrWrite = AreRetriesAllowed ( writeConcern , context , server ) && isRetryableWriteException ;
192- }
181+ var isRetryableReadException = RetryabilityHelper . IsRetryableReadException ( exception ) ;
182+ var isRetryableRead = context . RetryRequested && ! context . Binding . Session . IsInTransaction && isRetryableReadException ;
183+
184+ //TODO We can shortcircuit this
185+ var isRetryableWriteException = RetryabilityHelper . IsRetryableWriteException ( exception ) ;
186+ var isRetryableWrites = AreRetriesAllowed ( writeConcern , context , context . ChannelSource . ServerDescription ) && isRetryableWriteException ;
187+
188+ var isRetryableReadOrWrite = isRetryableRead || isRetryableWrites ;
193189
194- backoff = TimeSpan . Zero ;
195190 var isRetryableException = RetryabilityHelper . IsRetryableException ( exception ) ;
196191 var isSystemOverloadedException = RetryabilityHelper . IsSystemOverloadedException ( exception ) ;
197192
198-
199193 var isBackpressureRetry = isSystemOverloadedException
200194 && isRetryableException ;
201195
0 commit comments