From e206e34175c091a753c0e733abeda41b662241d4 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Wed, 8 Jul 2020 11:47:25 -0700 Subject: [PATCH] Add a warning if TurboModule init uses dispatch_sync for main queue Summary: When you require a TurboModule on thread that isn't the main thread, but the TurboModule requires main queue setup, we are forced to `dispatch_sync` the set up to the main queue. This is hazardous, because it can lead to deadlocks. Therefore, I'm migrating over a warning from the legacy infra that warns against this use-case. Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D21654637 fbshipit-source-id: 99dc45708c533603d2111fe6163d40e807d2a513 --- .../turbomodule/core/platform/ios/RCTTurboModuleManager.mm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm index 09d24f25ba..e0db1ecea8 100644 --- a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm +++ b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm @@ -396,6 +396,12 @@ static Class getFallbackClassFromName(const char *name) }; if ([self _requiresMainQueueSetup:moduleClass]) { + if (!RCTIsMainQueue()) { + RCTLogWarn( + @"TurboModule \"%@\" requires synchronous dispatch onto the main queue to be initialized. This may lead to deadlock.", + moduleClass); + } + RCTUnsafeExecuteOnMainQueueSync(work); } else { work();