summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorKshitij Gupta <kshitij.gupta@mongodb.com>2021-12-16 20:01:30 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-12-29 00:13:30 +0000
commit2772180b9312c0bd61c14f90fb644bf82e746e5d (patch)
tree169168b1e12fa8dc7508cb848a837b0e0348d3ce /src/mongo/db
parent34c6dc3755c98d8840a9b95c568dab517fafd729 (diff)
downloadmongo-2772180b9312c0bd61c14f90fb644bf82e746e5d.tar.gz
SERVER-62098: Guard access to healthCheckContexts with a mutex
(cherry picked from commit 85b301e1ad233e0448377b842cf63c1c7e134cde)
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/process_health/fault_manager.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/mongo/db/process_health/fault_manager.cpp b/src/mongo/db/process_health/fault_manager.cpp
index a8b18906236..43ec396d85b 100644
--- a/src/mongo/db/process_health/fault_manager.cpp
+++ b/src/mongo/db/process_health/fault_manager.cpp
@@ -349,10 +349,13 @@ FaultManager::~FaultManager() {
_taskExecutor->shutdown();
LOGV2(5936601, "Shutting down periodic health checks");
- for (auto& pair : _healthCheckContexts) {
- auto cbHandle = pair.second.resultStatus;
- if (cbHandle) {
- _taskExecutor->cancel(cbHandle.get());
+ {
+ stdx::lock_guard lock(_mutex);
+ for (auto& pair : _healthCheckContexts) {
+ auto cbHandle = pair.second.resultStatus;
+ if (cbHandle) {
+ _taskExecutor->cancel(cbHandle.get());
+ }
}
}
@@ -459,6 +462,7 @@ void FaultManager::healthCheck(HealthObserver* observer, std::shared_ptr<AtomicW
periodicThreadCbHandleStatus.isOK());
}
+ stdx::lock_guard lock(_mutex);
_healthCheckContexts.at(observer->getType()).resultStatus =
std::move(periodicThreadCbHandleStatus.getValue());
};
@@ -471,7 +475,11 @@ void FaultManager::healthCheck(HealthObserver* observer, std::shared_ptr<AtomicW
return healthCheckStatus;
};
- _healthCheckContexts.insert({observer->getType(), HealthCheckContext(nullptr, boost::none)});
+ {
+ stdx::lock_guard lock(_mutex);
+ _healthCheckContexts.insert(
+ {observer->getType(), HealthCheckContext(nullptr, boost::none)});
+ }
// If health observer is disabled, then do nothing and schedule another run (health observer may
// become enabled).
@@ -500,9 +508,10 @@ void FaultManager::healthCheck(HealthObserver* observer, std::shared_ptr<AtomicW
accept(status.getValue());
return status.getValue();
});
- auto futurePtr =
+
+ stdx::lock_guard lock(_mutex);
+ _healthCheckContexts.at(observer->getType()).result =
std::make_unique<ExecutorFuture<HealthCheckStatus>>(std::move(healthCheckFuture));
- _healthCheckContexts.at(observer->getType()).result = std::move(futurePtr);
}
void FaultManager::updateWithCheckStatus(HealthCheckStatus&& checkStatus) {