Skip to content

Commit

Permalink
Add a warning if TurboModule init uses dispatch_sync for main queue
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RSNara authored and facebook-github-bot committed Jul 8, 2020
1 parent cfa4260 commit e206e34
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ - (void)notifyAboutTurboModuleSetup:(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();
Expand Down

0 comments on commit e206e34

Please sign in to comment.