summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaMont Nelson <lamont.nelson@mongodb.com>2021-12-08 17:34:12 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-12-28 23:18:25 +0000
commit7f2a575a1a1fb90197dac5c125bfc03348355b7f (patch)
tree502853ae9f513776a96468ea440c2c1cb40c0d47
parent11649132c8a89b81ed9031166b8aad88c89a1495 (diff)
downloadmongo-7f2a575a1a1fb90197dac5c125bfc03348355b7f.tar.gz
SERVER-61956 fix data race when accessing the state machine's state
-rw-r--r--src/mongo/db/process_health/state_machine.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/mongo/db/process_health/state_machine.h b/src/mongo/db/process_health/state_machine.h
index 0980fd1045f..0d4a0ec33dc 100644
--- a/src/mongo/db/process_health/state_machine.h
+++ b/src/mongo/db/process_health/state_machine.h
@@ -95,6 +95,7 @@ public:
// Transitions the state machine into the initial state.
// Can only be called once.
void start() {
+ stdx::lock_guard<stdx::recursive_mutex> lk(_mutex);
tassertNotStarted();
_started = true;
@@ -108,6 +109,7 @@ public:
// Define a valid transition.
// Must be called prior to starting the state machine.
void validTransition(State from, State to) noexcept {
+ stdx::lock_guard<stdx::recursive_mutex> lk(_mutex);
tassertNotStarted();
auto& context = _states[from];
context.validTransitions.insert(to);
@@ -132,8 +134,8 @@ public:
// 2. For any hooks run as a result of accepting this message, no blocking calls are made
// involving shared resources with another thread that may call this function.
State accept(const OptionalMessageType& m) {
- tassertStarted();
stdx::lock_guard<stdx::recursive_mutex> lk(_mutex);
+ tassertStarted();
auto& handler = _current->stateHandler;
@@ -146,6 +148,7 @@ public:
// Return the current state.
State state() const {
+ stdx::lock_guard<stdx::recursive_mutex> lk(_mutex);
tassertStarted();
invariant(_current);
return _current->state();
@@ -226,6 +229,7 @@ public:
};
StateEventRegistryPtr registerHandler(StateHandlerPtr handler) {
+ stdx::lock_guard<stdx::recursive_mutex> lk(_mutex);
tassertNotStarted();
auto& context = _states[handler->state()];
context.stateHandler = std::move(handler);
@@ -233,6 +237,7 @@ public:
}
StateEventRegistryPtr registerHandler(State s, MessageHandler&& handler, bool isTransient) {
+ stdx::lock_guard<stdx::recursive_mutex> lk(_mutex);
tassertNotStarted();
auto& context = _states[s];
@@ -307,7 +312,7 @@ protected:
return getHandlerOrFatal(s);
}
- stdx::recursive_mutex _mutex;
+ mutable stdx::recursive_mutex _mutex;
bool _started;
State _initial;
StateContext* _current = nullptr;