diff options
author | Misha Tyulenev <misha@mongodb.com> | 2017-02-08 13:13:20 -0500 |
---|---|---|
committer | Misha Tyulenev <misha@mongodb.com> | 2017-02-08 13:13:57 -0500 |
commit | b65f66e20f7ba380b2202947b68db89d42c45931 (patch) | |
tree | 210570847fa3c716fc37913251eec303207813d0 /src/mongo/client/replica_set_monitor_manager.cpp | |
parent | bae38e4ebedfe66f66f3cef6ee0e9d12ad79b116 (diff) | |
download | mongo-b65f66e20f7ba380b2202947b68db89d42c45931.tar.gz |
SERVER-27940: fix deadlock in ReplicaSetMonitorManager on shutdown
Diffstat (limited to 'src/mongo/client/replica_set_monitor_manager.cpp')
-rw-r--r-- | src/mongo/client/replica_set_monitor_manager.cpp | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/src/mongo/client/replica_set_monitor_manager.cpp b/src/mongo/client/replica_set_monitor_manager.cpp index 773619086a4..561bcfded74 100644 --- a/src/mongo/client/replica_set_monitor_manager.cpp +++ b/src/mongo/client/replica_set_monitor_manager.cpp @@ -155,26 +155,39 @@ void ReplicaSetMonitorManager::removeMonitor(StringData setName) { } } - void ReplicaSetMonitorManager::shutdown() { - stdx::lock_guard<stdx::mutex> lk(_mutex); - if (_taskExecutor && !_isShutdown) { - LOG(1) << "Shutting down task executor used for monitoring replica sets"; - _taskExecutor->shutdown(); - _taskExecutor->join(); + + { + stdx::lock_guard<stdx::mutex> lk(_mutex); + if (!_taskExecutor || _isShutdown) { + return; + } _isShutdown = true; } + + LOG(1) << "Shutting down task executor used for monitoring replica sets"; + _taskExecutor->shutdown(); + _taskExecutor->join(); } void ReplicaSetMonitorManager::removeAllMonitors() { - stdx::lock_guard<stdx::mutex> lk(_mutex); - _monitors = ReplicaSetMonitorsMap(); + { + stdx::lock_guard<stdx::mutex> lk(_mutex); + _monitors = ReplicaSetMonitorsMap(); + if (!_taskExecutor || _isShutdown) { + return; + } + _isShutdown = true; + } + + LOG(1) << "Shutting down task executor used for monitoring replica sets"; + _taskExecutor->shutdown(); + _taskExecutor->join(); + _taskExecutor.reset(); - if (_taskExecutor) { - LOG(1) << "Shutting down task executor used for monitoring replica sets"; - _taskExecutor->shutdown(); - _taskExecutor->join(); - _taskExecutor.reset(); + { + stdx::lock_guard<stdx::mutex> lk(_mutex); + _isShutdown = false; } } |