summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2021-03-18 17:51:59 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-04-23 13:31:50 +0000
commit7f7a299321f22c0042226529fd0803292fdaf657 (patch)
tree5c314bfbb79e66c8b97092b8fc5d3a827e15eb8a /src/mongo/db/repl
parentc2295adab43675bfde8c9b2aa5795d9b7fccb6b0 (diff)
downloadmongo-7f7a299321f22c0042226529fd0803292fdaf657.tar.gz
SERVER-55007 Deadlock between step down and MongoDOperationContextSession
(cherry picked from commit 939178eb77d25dc234de03ac7d5dc98210514c7a)
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.cpp5
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp11
2 files changed, 16 insertions, 0 deletions
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp
index da72aaa2fb3..b0960927b8c 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl.cpp
@@ -2758,6 +2758,11 @@ void ReplicationCoordinatorImpl::_finishReplSetReconfig(OperationContext* opCtx,
_topCoord->prepareForUnconditionalStepDown();
lk.unlock();
+ // To prevent a deadlock between session checkout and RSTL lock taking, disallow new
+ // sessions from being checked out. Existing sessions currently checked out will be killed
+ // by the killOpThread.
+ ScopedBlockSessionCheckouts blockSessions(opCtx);
+
// Primary node won't be electable or removed after the configuration change.
// So, finish the reconfig under RSTL, so that the step down occurs safely.
arsd.emplace(this, opCtx, ReplicationCoordinator::OpsKillingStateTransitionEnum::kStepDown);
diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
index 0b32eacc507..bcdb1b7312b 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
@@ -53,6 +53,7 @@
#include "mongo/db/repl/topology_coordinator.h"
#include "mongo/db/repl/vote_requester.h"
#include "mongo/db/service_context.h"
+#include "mongo/db/session_catalog.h"
#include "mongo/platform/mutex.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
@@ -409,6 +410,11 @@ void ReplicationCoordinatorImpl::_stepDownFinish(
auto opCtx = cc().makeOperationContext();
+ // To prevent a deadlock between session checkout and RSTL lock taking, disallow new sessions
+ // from being checked out. Existing sessions currently checked out will be killed by the
+ // killOpThread.
+ ScopedBlockSessionCheckouts blockSessions(opCtx.get());
+
// kill all write operations which are no longer safe to run on step down. Also, operations that
// have taken global lock in S mode and operations blocked on prepare conflict will be killed to
// avoid 3-way deadlock between read, prepared transaction and step down thread.
@@ -644,6 +650,11 @@ void ReplicationCoordinatorImpl::_heartbeatReconfigFinish(
_topCoord->prepareForUnconditionalStepDown();
lk.unlock();
+ // To prevent a deadlock between session checkout and RSTL lock taking, disallow new
+ // sessions from being checked out. Existing sessions currently checked out will be killed
+ // by the killOpThread.
+ ScopedBlockSessionCheckouts blockSessions(opCtx.get());
+
// Primary node will be either unelectable or removed after the configuration change.
// So, finish the reconfig under RSTL, so that the step down occurs safely.
arsd.emplace(