[SERVER-65188] SessionsCollectionConfigServer does not check responses of scatterGatherVersionedTargetByRoutingTable() when creating indexes Created: 01/Apr/22  Updated: 29/Oct/23  Resolved: 12/May/22

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: None
Fix Version/s: 6.1.0-rc0

Type: Bug Priority: Major - P3
Reporter: Brett Nawrocki Assignee: Nandini Bhartiya
Resolution: Fixed Votes: 0
Labels: neweng, sharding-nyc-subteam1
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

Apply the below git patch and run the given resmoke command after building.

buildscripts/resmoke.py run --suite=sharding_auth jstests/sharding/configsvr_retries_createindex_on_stale_config.js

diff --git a/src/mongo/db/sessions_collection.cpp b/src/mongo/db/sessions_collection.cpp
index 88c75302220..38d35720ca4 100644
--- a/src/mongo/db/sessions_collection.cpp
+++ b/src/mongo/db/sessions_collection.cpp
@@ -43,8 +43,11 @@
 #include "mongo/db/repl/read_concern_args.h"
 #include "mongo/rpc/get_status_from_command_result.h"
 #include "mongo/s/write_ops/batched_command_response.h"
+#include "mongo/util/fail_point.h"
 
 namespace mongo {
+
+MONGO_FAIL_POINT_DEFINE(sessionsCollectionMakeBadCreateIndexCommand);
 namespace {
 
 // This batch size is chosen to ensure that we don't form requests larger than the 16mb limit.
@@ -276,7 +279,13 @@ BSONObj SessionsCollection::generateCreateIndexesCmd() {
     index.setExpireAfterSeconds(localLogicalSessionTimeoutMinutes * 60);
 
     CreateIndexesCommand createIndexes(NamespaceString::kLogicalSessionsNamespace);
-    createIndexes.setIndexes({index.toBSON()});
+    auto indexBson = index.toBSON();
+    sessionsCollectionMakeBadCreateIndexCommand.execute([&](const BSONObj& data) {
+        auto tmp = BSON("expireAfterSeconds"
+                        << "badValue");
+        indexBson = indexBson.addField(tmp.firstElement());
+    });
+    createIndexes.setIndexes({indexBson});
 
     return createIndexes.toBSON(BSON(WriteConcernOptions::kWriteConcernField
                                      << WriteConcernOptions::kInternalWriteDefault));
diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js
index dc55d3b0a5e..135fcadd430 100644
--- a/src/mongo/shell/shardingtest.js
+++ b/src/mongo/shell/shardingtest.js
@@ -1916,7 +1916,10 @@ var ShardingTest = function(params) {
     // Ensure that the sessions collection exists so jstests can run things with
     // logical sessions and test them. We do this by forcing an immediate cache refresh
     // on the config server, which auto-shards the collection for the cluster.
-    this.configRS.getPrimary().getDB("admin").runCommand({refreshLogicalSessionCacheNow: 1});
+    assert.commandWorked(this.configRS.getPrimary().getDB("admin").runCommand(
+        {configureFailPoint: "sessionsCollectionMakeBadCreateIndexCommand", mode: "alwaysOn"}));
+    assert.commandWorked(
+        this.configRS.getPrimary().getDB("admin").runCommand({refreshLogicalSessionCacheNow: 1}));
 
     // Ensure that all CSRS nodes are up to date. This is strictly needed for tests that use
     // multiple mongoses. In those cases, the first mongos initializes the contents of the 'config'

Sprint: Sharding 2022-05-02, Sharding NYC 2022-05-16
Participants:
Linked BF Score: 70
Story Points: 2

 Description   

SessionsCollectionConfigServer does not check responses of scatterGatherVersionedTargetByRoutingTable() when creating indexes. This can cause refreshLogicalSessionCacheNow to fail silently if it fails to create the indexes for some reason, leading to potentially surprising behavior if it is believed to have succeeded. An example of this can be see in BF-24691.



 Comments   
Comment by Githook User [ 12/May/22 ]

Author:

{'name': 'nandinibhartiyaMDB', 'email': '104035932+nandinibhartiyaMDB@users.noreply.github.com', 'username': 'nandinibhartiyaMDB'}

Message: SERVER-65188: Check shard response ok in SessionsCollectionConfigServer
Branch: master
https://github.com/mongodb/mongo/commit/df995d36642a75186dfc01198bc0d6f2d1030ce2

Comment by Max Hirschhorn [ 11/Apr/22 ]

Acceptance criteria:

  • See if it is trivial to make scatterGatherVersionedTargetByRoutingTable() [[nodiscard]] to prevent this kind of misuse in the future.
  • Ensure refreshLogicalSessionCacheNow command returns an error if the createIndexes command fails. This will also mean propagating the exception from setupSessionsCollection.
Generated at Thu Feb 08 06:02:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.