| Steps To Reproduce: |
I've created a patch which instruments the server code with a sleep in order to reproduce this more reliably. Apply the following patch:
diff --git a/src/mongo/db/kill_sessions_common.h b/src/mongo/db/kill_sessions_common.h
|
index 95361aa5cf..7b24b579c8 100644
|
--- a/src/mongo/db/kill_sessions_common.h
|
+++ b/src/mongo/db/kill_sessions_common.h
|
@@ -101,6 +101,9 @@ public:
|
ScopedKillAllSessionsByPatternImpersonator impersonator(_opCtx, *pattern);
|
|
auto cursors = mgr.getCursorsForSession(session);
|
+ std::cout << "!!! sleeping after getting cursors for session" << std::endl;
|
+ sleepFor(Seconds{10});
|
+ std::cout << "!!! waking up" << std::endl;
|
for (const auto& id : cursors) {
|
try {
|
_eraser(mgr, id);
|
Then, start a sharded cluster. Run the following against the mongos from one shell. This opens a logical session and creates a cursor within that session:
var session = db.getMongo().startSession();
|
var sessionDb = session.getDatabase(db.getName());
|
sessionDb.c.insert({a: 1});
|
sessionDb.c.insert({a: 1});
|
sessionDb.c.insert({a: 1});
|
var cursor = sessionDb.c.find().batchSize(2);
|
cursor.next();
|
From another shell, verify that there is an idle cursor, and obtain the lsid associated with the cursor:
use admin
|
db.aggregate([{$currentOp: {idleCursors: true}}, {$match: {type: "idleCursor"}}]);
|
Then, from the second shell, issue the admin command to kill the session. This will hang for 10 seconds due to the instrumentation above.
db.adminCommand({killSessions: [ { "id": <lsid> } ]});
|
While the killSessions command is hanging, close the cursor in the first shell:
In a debug build, this will trip an assertion in the boost::optional code checking that the caller does not attempt to call get() when the value of the optional is boost::none:
s20005| mongos: src/third_party/boost-1.69.0/boost/optional/optional.hpp:1207: boost::optional::reference_type boost::optional<mongo::NamespaceString>::get() [T = mongo::NamespaceString]: Assertion `this->is_initialized()' failed.
|
|