summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zhang <jason.zhang@mongodb.com>2021-02-11 19:23:02 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-02-17 15:21:26 +0000
commit0f7281ffd6bf5f700ff9d0f6163beccf6803a58a (patch)
tree7c525eeb5eaa293961c4c1ff01bedeca39008011
parent3dc51b7724b0d8bef702a882c42161d766b179d5 (diff)
downloadmongo-0f7281ffd6bf5f700ff9d0f6163beccf6803a58a.tar.gz
SERVER-53995 ReplicaSetMonitor shared_ptr instance should be freed outside of mutex scope
-rw-r--r--src/mongo/client/replica_set_monitor_manager.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/mongo/client/replica_set_monitor_manager.cpp b/src/mongo/client/replica_set_monitor_manager.cpp
index 346a9e6a1c3..0d1d434734e 100644
--- a/src/mongo/client/replica_set_monitor_manager.cpp
+++ b/src/mongo/client/replica_set_monitor_manager.cpp
@@ -205,6 +205,11 @@ shared_ptr<ReplicaSetMonitor> ReplicaSetMonitorManager::getOrCreateMonitor(
}
shared_ptr<ReplicaSetMonitor> ReplicaSetMonitorManager::getMonitorForHost(const HostAndPort& host) {
+ // Hold the shared_ptrs for each of the ReplicaSetMonitors to extend the lifetime of the
+ // ReplicaSetMonitor objects to ensure that we do not call their destructors while still holding
+ // the mutex.
+ vector<shared_ptr<ReplicaSetMonitor>> rsmPtrs;
+
stdx::lock_guard<Latch> lk(_mutex);
for (auto entry : _monitors) {
@@ -212,6 +217,7 @@ shared_ptr<ReplicaSetMonitor> ReplicaSetMonitorManager::getMonitorForHost(const
if (monitor && monitor->contains(host)) {
return monitor;
}
+ rsmPtrs.push_back(std::move(monitor));
}
return shared_ptr<ReplicaSetMonitor>();