Skip to content

Commit 73cd828

Browse files
RSNarafacebook-github-bot
authored andcommitted
Take 2: Mitigate deadlock hazard in RCTUtils.m (#50807)
Summary: Pull Request resolved: #50807 This structure is unsafe: ``` // In each native module: +load dispatch_once NSBundle mainBundle ``` NSBundle mainBundle itself uses dispatch_once during initialization. If that initialization triggers a native module class load, we could end up with a circular dependency chain. This could deadlock the application. ## Changes Just remove the dispatch_once. Getting the NSBundle mainBundle is very efficient after the first access. And NSBundle objectForInfoDictionaryKey is also very efficient. Created from CodeHub with https://fburl.com/edit-in-codehub Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D73265906
1 parent 5fd5188 commit 73cd828

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

packages/react-native/React/Base/RCTUtils.mm

+5-15
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,10 @@
3535
BOOL RCTIsHomeAssetURL(NSURL *__nullable imageURL);
3636

3737
// Whether the New Architecture is enabled or not
38-
static BOOL _newArchEnabled = false;
3938
BOOL RCTIsNewArchEnabled(void)
4039
{
41-
static dispatch_once_t onceToken;
42-
dispatch_once(&onceToken, ^{
43-
NSNumber *rctNewArchEnabled = (NSNumber *)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTNewArchEnabled"];
44-
_newArchEnabled = rctNewArchEnabled == nil || rctNewArchEnabled.boolValue;
45-
});
46-
return _newArchEnabled;
40+
NSNumber *rctNewArchEnabled = (NSNumber *)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTNewArchEnabled"];
41+
return rctNewArchEnabled == nil || rctNewArchEnabled.boolValue;
4742
}
4843
void RCTSetNewArchEnabled(BOOL enabled)
4944
{
@@ -52,16 +47,11 @@ void RCTSetNewArchEnabled(BOOL enabled)
5247
// whether the New Arch is enabled or not.
5348
}
5449

55-
static BOOL _legacyWarningEnabled = true;
5650
BOOL RCTAreLegacyLogsEnabled(void)
5751
{
58-
static dispatch_once_t onceToken;
59-
dispatch_once(&onceToken, ^{
60-
NSNumber *rctNewArchEnabled =
61-
(NSNumber *)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTLegacyWarningsEnabled"];
62-
_legacyWarningEnabled = rctNewArchEnabled.boolValue;
63-
});
64-
return _legacyWarningEnabled;
52+
NSNumber *rctNewArchEnabled =
53+
(NSNumber *)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTLegacyWarningsEnabled"];
54+
return rctNewArchEnabled.boolValue;
6555
}
6656

6757
static NSString *__nullable _RCTJSONStringifyNoRetry(id __nullable jsonObject, NSError **error)

0 commit comments

Comments
 (0)