@@ -38,6 +38,7 @@ import {
3838} from '../utils' ;
3939import { AggregateOperation } from './aggregate' ;
4040import { AbstractOperation , Aspect , RetryContext } from './operation' ;
41+ import { RunCommandOperation } from './run_command' ;
4142
4243const MMAPv1_RETRY_WRITES_ERROR_CODE = MONGODB_ERROR_CODES . IllegalOperation ;
4344const 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