@@ -59,7 +59,7 @@ type ResultTypeFromOperation<TOperation extends AbstractOperation> = ReturnType<
5959 * The expectation is that this function:
6060 * - Connects the MongoClient if it has not already been connected, see {@link autoConnect}
6161 * - Creates a session if none is provided and cleans up the session it creates
62- * - Tries an operation and retries under certain conditions, see {@link tryOperation }
62+ * - Tries an operation and retries under certain conditions, see {@link executeOperationWithRetries }
6363 *
6464 * @typeParam T - The operation's type
6565 * @typeParam TResult - The type of the operation's result, calculated from T
@@ -129,7 +129,7 @@ export async function executeOperation<
129129 } ) ;
130130
131131 try {
132- return await tryOperation ( operation , {
132+ return await executeOperationWithRetries ( operation , {
133133 topology,
134134 timeoutContext,
135135 session,
@@ -193,7 +193,10 @@ type RetryOptions = {
193193 *
194194 * @param operation - The operation to execute
195195 * */
196- async function tryOperation < T extends AbstractOperation , TResult = ResultTypeFromOperation < T > > (
196+ async function executeOperationWithRetries <
197+ T extends AbstractOperation ,
198+ TResult = ResultTypeFromOperation < T >
199+ > (
197200 operation : T ,
198201 { topology, timeoutContext, session, readPreference } : RetryOptions
199202) : Promise < TResult > {
@@ -246,7 +249,7 @@ async function tryOperation<T extends AbstractOperation, TResult = ResultTypeFro
246249 const maxNonOverloadRetryAttempts = willRetry ? ( timeoutContext . csotEnabled ( ) ? Infinity : 2 ) : 1 ;
247250 let previousOperationError : MongoError | undefined ;
248251 let previousServer : ServerDescription | undefined ;
249- const nonOverloadRetryAttempt = 0 ;
252+ let nonOverloadRetryAttempt = 0 ;
250253
251254 let systemOverloadRetryAttempt = 0 ;
252255 const maxSystemOverloadRetryAttempts = 5 ;
@@ -306,8 +309,9 @@ async function tryOperation<T extends AbstractOperation, TResult = ResultTypeFro
306309 signal : operation . options . signal
307310 } ) ;
308311 } else {
312+ nonOverloadRetryAttempt ++ ;
309313 // we have no more retry attempts, throw.
310- if ( nonOverloadRetryAttempt >= maxNonOverloadRetryAttempts ) {
314+ if ( nonOverloadRetryAttempt > maxNonOverloadRetryAttempts ) {
311315 throw previousOperationError ;
312316 }
313317
0 commit comments