From 1c1fa5b909f708ffda1eea92d1dad49075ad204c Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Tue, 10 Mar 2020 19:55:59 -0700 Subject: [PATCH] Make main queue setup synchronous Summary: This can cause a deadlock if the main thread synchronously calls into some JS that creates a TurboModule. However, this is also the behaviour of legacy NativeModules. Furthermore, this also greatly simplifies how we'll fix async method invocation in TurboModules: T55255146. Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D20364251 fbshipit-source-id: d0db85665506f08c51c2f33a123e69960923e7f3 --- .../core/platform/ios/RCTTurboModuleManager.mm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm index c5a46e004d8..8553041e814 100644 --- a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm +++ b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm @@ -17,6 +17,7 @@ #import #import #import +#import #import #import @@ -326,7 +327,14 @@ static Class getFallbackClassFromName(const char *name) if ([[module class] respondsToSelector:@selector(requiresMainQueueSetup)] && [[module class] requiresMainQueueSetup]) { - dispatch_async(dispatch_get_main_queue(), setupTurboModule); + /** + * If the main thread synchronously calls into JS that creates a TurboModule, + * we could deadlock. This behaviour is migrated over from the legacy NativeModule + * system. + * + * TODO(T63807674): Investigate the right migration plan off of this + */ + RCTUnsafeExecuteOnMainQueueSync(setupTurboModule); } else { setupTurboModule(); }