Skip to content

Commit 62f20fc

Browse files
done
1 parent 73a3587 commit 62f20fc

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/operations/execute_operation.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
} from '../utils';
3939
import { AggregateOperation } from './aggregate';
4040
import { AbstractOperation, Aspect, RetryContext } from './operation';
41+
import { RunCommandOperation } from './run_command';
4142

4243
const MMAPv1_RETRY_WRITES_ERROR_CODE = MONGODB_ERROR_CODES.IllegalOperation;
4344
const MMAPv1_RETRY_WRITES_ERROR_MESSAGE =
@@ -269,6 +270,10 @@ async function executeOperationWithRetries<
269270
});
270271
}
271272

273+
const canRetryBackpressureError =
274+
(operation.hasAspect(Aspect.WRITE_OPERATION) && topology.s.options.retryWrites) ||
275+
(operation.hasAspect(Aspect.READ_OPERATION) && topology.s.options.retryReads) ||
276+
(operation instanceof RunCommandOperation && topology.s.options.retryReads);
272277
// TODO: think about whether or not willRetry checks are necessary here.
273278
const isRetryable =
274279
// bulk write commands are retryable if all operations in the batch are retryable
@@ -279,7 +284,7 @@ async function executeOperationWithRetries<
279284
(hasWriteAspect && willRetryWrite && isRetryableWriteError(previousOperationError)) ||
280285
(hasReadAspect && willRetryRead && isRetryableReadError(previousOperationError)) ||
281286
// if we have a retryable, system overloaded error, we can retry
282-
(willRetry &&
287+
(canRetryBackpressureError &&
283288
previousOperationError.hasErrorLabel(MongoErrorLabel.SystemOverloadedError) &&
284289
previousOperationError.hasErrorLabel(MongoErrorLabel.RetryableError));
285290

0 commit comments

Comments
 (0)