react-native-macos/React/Modules
Saad Najmi fcead14b0e Fix Deadlock in RCTi18nUtil (iOS) (#31032)
Summary:
Note: PR to react-native-macos here https://github.com/microsoft/react-native-macos/pull/733

Internally in Microsoft code, we ran into a deadlock where the main queue and the UIManager queue were both trying to access `[RCTI18nUtil sharedInstance]`, and were blocked on each other. This is similar to an earlier issue with RCTScreenScale decsribed [here](https://github.com/facebook/react-native/issues/18096).

To summarize:
1- RCTShadowView (on the UIManager queue) and RCTView (on the main queue) both try to access `[RCTI18nUtil sharedInstance]`
2- The UIManager thread gets there first, and lazily initializes the sharedInstance. Meanwhile, the main thread is waiting on a lock possessed by the UIManager thread
3- As part of the initialization, we set an NSUserDefault, which seems to require the (blocked) main thread.
4- Deadlock.

For whatever reason, this only happens on debug. I did not figure out why, but I do know based on [this comment](https://github.com/facebook/react-native/issues/18096#issuecomment-368718081), that the UIManagerQueue should never block the main queue.

The fix is to not use NSUserDefaults, and simpy use atomic properties instead. We get the thread safety for free, and it also simplifies the code somewhat without changing the public API. The downside is values aren't persisted anymore, but I do not think that was necessary / intended.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[iOS] [Fixed] - Fix deadlock on RCTi18nUtil

Pull Request resolved: https://github.com/facebook/react-native/pull/31032

Test Plan:
Ran the RTLExample in RNTester, and ensured switching to RTL still worked, and that setting forceRTL would still work after reloading the bundle.

https://user-images.githubusercontent.com/6722175/108775429-aefdae80-7526-11eb-9a89-3114f7ddc2af.mov

Reviewed By: javache

Differential Revision: D29522152

Pulled By: RSNara

fbshipit-source-id: 160840f63a7b1d6721b0fd8294fb11990a4509fa
2021-08-06 02:44:50 -07:00
..
RCTEventEmitter.h Bridgeless Mode: Migrate modules away from invokeJS 2021-05-14 09:22:58 -07:00
RCTEventEmitter.m Bridgeless Mode: Migrate modules away from invokeJS 2021-05-14 09:22:58 -07:00
RCTI18nUtil.h Fix Deadlock in RCTi18nUtil (iOS) (#31032) 2021-08-06 02:44:50 -07:00
RCTI18nUtil.m Fix Deadlock in RCTi18nUtil (iOS) (#31032) 2021-08-06 02:44:50 -07:00
RCTLayoutAnimation.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTLayoutAnimation.m remove most of tvOS remnants from the code (#29407) 2020-09-28 21:26:41 -07:00
RCTLayoutAnimationGroup.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTLayoutAnimationGroup.m Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTRedBoxExtraDataViewController.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTRedBoxExtraDataViewController.m remove most of tvOS remnants from the code (#29407) 2020-09-28 21:26:41 -07:00
RCTSurfacePresenterStub.h Remove integration between Paper and Fabric's UIManager 2020-06-29 15:26:31 -07:00
RCTSurfacePresenterStub.m Fabric: Fixing incorrect retaining policy for RCTSurfacePreseter (crash in RCTNativeAnimatedModule) 2020-01-13 13:36:36 -08:00
RCTUIManager.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTUIManager.m iOS: adding a few warning/enforcement for the new architecture 2021-05-03 21:31:19 -07:00
RCTUIManagerObserverCoordinator.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTUIManagerObserverCoordinator.mm Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTUIManagerUtils.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTUIManagerUtils.m Fix Xcode warnings in React-Core pod (#29622) 2020-09-09 12:48:09 -07:00