-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: 8.0.9
-
Component/s: None
-
Catalog and Routing
-
ALL
-
π₯ DDL
-
None
-
None
-
None
-
None
-
None
-
None
I found a logical error in ShardingCatalogManager::createDatabase() in MongoDB 8.0.9:
In this method, the retries variable is initialized to 10 inside the while (true) loop:
{{while (true) {
// ...
auto retries = 10;
try
// ...
if (optResolvedPrimaryShard) { throw; } else {
retries--;
if (retries > 0) { continue; } else {
LOGV2_WARNING(8917901,
"Exhausted retries trying to commit create database",
"dbName"_attr = dbName);
throw;
}
}
}
}}}
Since retries is declared inside the loop, it is reinitialized to 10 on every iteration.
When _commitCreateDatabase() throws ErrorCodes::ShardNotFound and no primary shard was explicitly specified, retries is decremented from 10 to 9. The condition retries > 0 is therefore always true, and the continue statement starts another iteration with retries reset to 10.
As a result, the retry counter never reaches zero, and the branch responsible for reporting exhausted retry attempts is unreachable.
If ShardNotFound continues to occur, the function may keep retrying indefinitely instead of stopping after the intended number of attempts. This may lead to excessive repeated operations and failure to terminate the database creation attempt as intended.
A possible fix is to move the initialization of retries outside the loop:
{{auto retries = 10;
while (true) {
// ...
try { return _commitCreateDatabase(opCtx, dbName, candidatePrimaryShardId); }
catch (const ExceptionFor<ErrorCodes::ShardNotFound>& ex) {
// ...
if (optResolvedPrimaryShard)
else {
retries--;
if (retries > 0)
else {
LOGV2_WARNING(8917901,
"Exhausted retries trying to commit create database",
"dbName"_attr = dbName);
throw;
}
}
}
}}}
This ensures that the retry counter is preserved across iterations and the retry limit is enforced.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Reporter: Grebennikov Aleksandr (grebennikov@bmstu.ru
)