Skip to content

Commit a6f5100

Browse files
RSNarafacebook-github-bot
authored andcommitted
Mitigate deadlock hazard in RCTUtils.m
Summary: 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: cipolleschi Differential Revision: D73058551 fbshipit-source-id: 9d14b5556748288227cfb93940f79d44997d7b47
1 parent 929099f commit a6f5100

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

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

+2-15
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,9 @@
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+
return ((NSNumber *)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTNewArchEnabled"]).boolValue;
4741
}
4842
void RCTSetNewArchEnabled(BOOL enabled)
4943
{
@@ -52,16 +46,9 @@ void RCTSetNewArchEnabled(BOOL enabled)
5246
// whether the New Arch is enabled or not.
5347
}
5448

55-
static BOOL _legacyWarningEnabled = true;
5649
BOOL RCTAreLegacyLogsEnabled(void)
5750
{
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;
51+
return ((NSNumber *)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"RCTLegacyWarningsEnabled"]).boolValue;
6552
}
6653

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

0 commit comments

Comments
 (0)