summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/ops/write_ops_exec.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/mongo/db/ops/write_ops_exec.cpp b/src/mongo/db/ops/write_ops_exec.cpp
index 9e457ebb0e5..5f0096162e4 100644
--- a/src/mongo/db/ops/write_ops_exec.cpp
+++ b/src/mongo/db/ops/write_ops_exec.cpp
@@ -722,6 +722,10 @@ static SingleWriteResult performSingleUpdateOpWithDupKeyRetry(OperationContext*
: PlanExecutor::YIELD_AUTO);
size_t numAttempts = 0;
+
+ // Upper bound on the number of retries allowed. This prevents the server from getting stuck
+ // in an infinite loop when trying to upsert invalid BSON (see SERVER-60897 for details).
+ constexpr size_t kMaxNumAttempts = 1000;
while (true) {
++numAttempts;
@@ -736,6 +740,10 @@ static SingleWriteResult performSingleUpdateOpWithDupKeyRetry(OperationContext*
uassertStatusOK(parsedUpdate.parseQueryToCQ());
}
+ if (numAttempts >= kMaxNumAttempts) {
+ throw;
+ }
+
if (!UpdateStage::shouldRetryDuplicateKeyException(
parsedUpdate, *ex.extraInfo<DuplicateKeyErrorInfo>())) {
throw;