summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2021-03-18 17:51:59 +0000
committerRandolph Tan <randolph@10gen.com>2021-04-23 13:46:45 +0000
commit8c564e925ae99f4de77e64ade90e214f3dda4ba6 (patch)
treee307436a1bdc059de61b7c504523727f1853526d
parent77530ffba57e2affb7574da8d04b7e91a66aa248 (diff)
downloadmongo-8c564e925ae99f4de77e64ade90e214f3dda4ba6.tar.gz
SERVER-55007 Deadlock between step down and MongoDOperationContextSession
(cherry picked from commit 939178eb77d25dc234de03ac7d5dc98210514c7a)
-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 16bc218e87e..d8e51995fcb 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl.cpp
@@ -3431,6 +3431,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 1665e83207a..c36478959e9 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
@@ -56,6 +56,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/db/storage/control/journal_flusher.h"
#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
@@ -455,6 +456,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.
@@ -739,6 +745,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(