Skip to content

Make RCTDeviceInfo constants atomic so getConstants can't read a released dictionary - #60017

Merged
meta-codesync[bot] merged 2 commits into
react:mainfrom
lazerg:fix/issue-60014-device-info-constants-race
Nov 16, 2026
Merged

meta-codesync[bot] merged 2 commits into
react:mainfrom
lazerg:fix/issue-60014-device-info-constants-race

Conversation

@lazerg

@lazerg lazerg commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Since invalidateCachedConstants started rewriting _constants on resize, orientation and app activation, getConstants can crash with EXC_BAD_ACCESS on 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 makes constants an 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.getConstants caused by a data race on the cached constants

Test 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, copy property 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 -StormConstants without it, 0/10 with it. Their patch also moved didReceiveNewContentSizeMultiplier to the main queue, which I left out because #57989 already covers it. The file is clang-format clean.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 16, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 16, 2026
@github-actions

Copy link
Copy Markdown

Visual regression

No visual differences at 423d302d5e0a.

android: no capture

@meta-codesync

meta-codesync Bot commented Nov 16, 2026

Copy link
Copy Markdown

@javache has imported this pull request. If you are a Meta employee, you can view this in D132239323.

@meta-codesync
meta-codesync Bot merged commit 5534fd9 into react:main Nov 16, 2026
86 checks passed
@react-native-bot

Copy link
Copy Markdown
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?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[iOS] EXC_BAD_ACCESS in NativeDeviceInfo.getConstants: data race on RCTDeviceInfo's _constants (0.88+)

3 participants