diff options
author | Mihai Andrei <mihai.andrei@10gen.com> | 2021-11-19 11:12:45 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-12-03 22:14:17 +0000 |
commit | f65ce5e25c0b26a00d091a4d24eec1a8b3a4c016 (patch) | |
tree | b6721a231fcf7d9d2ec5d2775b30f2dd4015d386 | |
parent | c797110b90fd5d950fa5d78aa26ae198c76883c6 (diff) | |
download | mongo-f65ce5e25c0b26a00d091a4d24eec1a8b3a4c016.tar.gz |
SERVER-60897 Place upper bound on number of duplicate key retries for updatesr4.2.18-rc0r4.2.18
-rw-r--r-- | src/mongo/db/ops/write_ops_exec.cpp | 8 |
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; |