Repository navigation
Make RCTDeviceInfo constants atomic so getConstants can't read a released dictionary - #60017
Merged
meta-codesync[bot] merged 2 commits intoNov 16, 2026
Conversation
Visual regressionNo visual differences at android: no capture |
javache
approved these changes
Nov 16, 2026
|
@javache has imported this pull request. If you are a Meta employee, you can view this in D132239323. |
Collaborator
|
This pull request was successfully merged by @lazerg in 5534fd9 When will my fix make it into a release? | How to file a pick request? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Since
invalidateCachedConstantsstarted rewriting_constantson resize, orientation and app activation,getConstantscan crash withEXC_BAD_ACCESSon the JS thread. It's a sync TurboModule method, so it reads the ivar on the JS thread while the main thread may be swapping it out and releasing the old dictionary. If the release lands between the load and the retain, JS retains a freed object. This makesconstantsan atomic property and uses it at every read and write, so a reader always retains the dictionary before a writer can release it. It doesn't add a JS to main sync hop.Fixes #60014
Changelog:
[IOS] [FIXED] - Fix a crash in
NativeDeviceInfo.getConstantscaused by a data race on the cached constantsTest Plan:
I don't have Xcode on this machine, so I couldn't build RNTester. I checked the pattern with a small ARC program: one thread reassigns a dictionary ivar in a loop and another reads it through a getter. With a plain ivar it segfaults on 3 of 3 runs. With an
atomic, copyproperty it survives 3 of 3 runs, about 50M reads each. The issue author ran a similar patch in their reproducer (https://github.com/jeremy-robotsson/rn-deviceinfo-constants-race): 10/10 crashes with-StormConstantswithout it, 0/10 with it. Their patch also moveddidReceiveNewContentSizeMultiplierto the main queue, which I left out because #57989 already covers it. The file is clang-format clean.