(operation: AbstractOperation, error: MongoError)
| 378 | ); |
| 379 | |
| 380 | function canRetry(operation: AbstractOperation, error: MongoError) { |
| 381 | // SystemOverloadedError is retryable, but must respect retryReads/retryWrites settings |
| 382 | // Check topology options directly (not operation.canRetryRead/Write) because backpressure |
| 383 | // expands retry support beyond traditional retryable reads/writes |
| 384 | // NOTE: Unlike traditional retries, backpressure retries ARE allowed inside transactions |
| 385 | if ( |
| 386 | error.hasErrorLabel(MongoErrorLabel.SystemOverloadedError) && |
| 387 | error.hasErrorLabel(MongoErrorLabel.RetryableError) |
| 388 | ) { |
| 389 | // runCommand requires BOTH retryReads and retryWrites to be enabled (per spec step 2.4) |
| 390 | if (operation instanceof RunCommandOperation) { |
| 391 | return topology.s.options.retryReads && topology.s.options.retryWrites; |
| 392 | } |
| 393 | |
| 394 | // Write-stage aggregates ($out/$merge) require retryWrites |
| 395 | if (operation instanceof AggregateOperation && operation.hasWriteStage) { |
| 396 | return topology.s.options.retryWrites; |
| 397 | } |
| 398 | |
| 399 | // For other operations, check if retries are enabled based on operation type |
| 400 | const canRetryAsRead = hasReadAspect && topology.s.options.retryReads; |
| 401 | const canRetryAsWrite = hasWriteAspect && topology.s.options.retryWrites; |
| 402 | return canRetryAsRead || canRetryAsWrite; |
| 403 | } |
| 404 | |
| 405 | // run command is only retryable if we get retryable overload errors |
| 406 | if (operation instanceof RunCommandOperation) { |
| 407 | return false; |
| 408 | } |
| 409 | |
| 410 | // batch operations are only retryable if the batch is retryable |
| 411 | if (operation.hasAspect(Aspect.COMMAND_BATCHING)) { |
| 412 | return operation.canRetryWrite && isRetryableWriteError(error); |
| 413 | } |
| 414 | |
| 415 | return ( |
| 416 | (hasWriteAspect && willRetryWrite && isRetryableWriteError(error)) || |
| 417 | (hasReadAspect && willRetryRead && isRetryableReadError(error)) |
| 418 | ); |
| 419 | } |
| 420 | } |
no test coverage detected