diff options
author | Jason Zhang <jason.zhang@mongodb.com> | 2021-02-11 19:23:02 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-02-17 15:21:26 +0000 |
commit | 0f7281ffd6bf5f700ff9d0f6163beccf6803a58a (patch) | |
tree | 7c525eeb5eaa293961c4c1ff01bedeca39008011 /src/mongo/client/replica_set_monitor_manager.cpp | |
parent | 3dc51b7724b0d8bef702a882c42161d766b179d5 (diff) | |
download | mongo-0f7281ffd6bf5f700ff9d0f6163beccf6803a58a.tar.gz |
SERVER-53995 ReplicaSetMonitor shared_ptr instance should be freed outside of mutex scope
Diffstat (limited to 'src/mongo/client/replica_set_monitor_manager.cpp')
-rw-r--r-- | src/mongo/client/replica_set_monitor_manager.cpp | 6 |
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>(); |