Skip to content

Commit 4751171

Browse files
zeyapfacebook-github-bot
authored andcommitted
Fix RCTInstance self-deadlock during invalidate
Summary: `-[RCTInstance invalidate]` held `_invalidationMutex` while it synchronously called `[_surfacePresenter suspend]`. Stopping surfaces notifies mount observers on the calling thread, and any observer that reaches `callFunctionOnJSModule:` (e.g. `RCTLog` forwarding to JS in debug builds) blocks forever on the same non-recursive mutex. Release the mutex after setting `_valid = false` and unregistering from the inspector, before `suspend`. Re-entrant calls now see `!_valid` and return. Changelog: [iOS][Fixed] - Fix deadlock in `RCTInstance` invalidation when a surface observer calls into JS Differential Revision: D125706316
1 parent 11d5dd0 commit 4751171

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

  • packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon

‎packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,15 @@ - (void)callFunctionOnJSModule:(NSString *)moduleName method:(NSString *)method
183183

184184
- (void)invalidate
185185
{
186-
std::lock_guard<std::mutex> lock(_invalidationMutex);
187-
_valid = false;
188-
if (_reactInstance) {
189-
_reactInstance->unregisterFromInspector();
186+
{
187+
std::lock_guard<std::mutex> lock(_invalidationMutex);
188+
_valid = false;
189+
if (_reactInstance) {
190+
_reactInstance->unregisterFromInspector();
191+
}
190192
}
193+
// suspend shouldn't be called under _invalidationMutex: it notifies surface observers,
194+
// which can call callFunctionOnJSModule and deadlock on the same mutex.
191195
[_surfacePresenter suspend];
192196
[_jsThreadManager dispatchToJSThread:^{
193197
/**

0 commit comments

Comments
 (0)