Skip to content

Commit d021000

Browse files
MartinSherburnfacebook-github-bot
authored andcommitted
Fix race condition in Inspector shutdown
Summary: The `state_` member variable was getting destroyed before the `executor_` (because `state_` is declared after `executor_` https://stackoverflow.com/questions/2254263/order-of-member-constructor-and-destructor-calls). This lead to a race condition where items still pending on the `executor_` thread could try to run and access `state_` after it had already been reset. Changelog: [General][Fixed] - Fix race condition in Debug Inspector shutdown Reviewed By: mhorowitz Differential Revision: D24705062 fbshipit-source-id: e575d66322ab980b1a8c3e6083a0b3d40b9c944b
1 parent 8e956b3 commit d021000

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

ReactCommon/hermes/inspector/Inspector.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ Inspector::Inspector(
132132
}
133133

134134
Inspector::~Inspector() {
135-
// TODO: think about expected detach flow
136135
debugger_.setEventObserver(nullptr);
137136
}
138137

ReactCommon/hermes/inspector/Inspector.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,6 @@ class Inspector : public facebook::hermes::debugger::EventObserver,
319319
facebook::hermes::debugger::Debugger &debugger_;
320320
InspectorObserver &observer_;
321321

322-
// All client methods (e.g. enable, setBreakpoint, resume, etc.) are executed
323-
// on executor_ to prevent deadlocking on mutex_. See the implementation for
324-
// more comments on the threading invariants used in this class.
325-
std::unique_ptr<folly::Executor> executor_;
326-
327322
// All of the following member variables are guarded by mutex_.
328323
std::mutex mutex_;
329324
std::unique_ptr<InspectorState> state_;
@@ -360,6 +355,12 @@ class Inspector : public facebook::hermes::debugger::EventObserver,
360355
// Are we currently waiting for a debugger to attach, because we
361356
// requested 'pauseOnFirstStatement'?
362357
bool awaitingDebuggerOnStart_;
358+
359+
// All client methods (e.g. enable, setBreakpoint, resume, etc.) are executed
360+
// on executor_ to prevent deadlocking on mutex_. See the implementation for
361+
// more comments on the threading invariants used in this class.
362+
// NOTE: This needs to be declared LAST because it should be destroyed FIRST.
363+
std::unique_ptr<folly::Executor> executor_;
363364
};
364365

365366
} // namespace inspector

0 commit comments

Comments
 (0)