diff options
author | Randolph Tan <randolph@10gen.com> | 2021-03-18 17:51:59 +0000 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2021-04-23 13:46:45 +0000 |
commit | 8c564e925ae99f4de77e64ade90e214f3dda4ba6 (patch) | |
tree | e307436a1bdc059de61b7c504523727f1853526d | |
parent | 77530ffba57e2affb7574da8d04b7e91a66aa248 (diff) | |
download | mongo-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.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp | 11 |
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( |