Skip to content

Make Node::owner_ a relaxed atomic pointer - #2094

Open
tjzel wants to merge 1 commit into
react:mainfrom
tjzel:atomic-owner
Open

tjzel wants to merge 1 commit into
react:mainfrom
tjzel:atomic-owner

Conversation

@tjzel

@tjzel tjzel commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Note

This pull request was authored by AI on behalf of @tjzel.

Summary

X-link: react/react-native#60106

A Yoga node shared between two trees can have its owner_ read by a layout pass on one thread while a clone of its previous owner, on another thread, rewrites it. In React Native this happens when two ShadowTree::commit calls overlap: the clone and layoutIfNeeded run outside the revision mutex, YogaLayoutableShadowNode::updateYogaChildrenOwnersIfNeeded writes a sentinel into the owner of shared children, and the other commit reads the owner in Node::cloneChildrenIfNeeded and YGNodeGetOwner. owner_ is a plain Node*, so this is a data race; ThreadSanitizer reports it on every run of the react-native-reanimated test suite (report in the linked issue).

Loads and stores of the owner now go through std::atomic<Node*> with relaxed ordering, wrapped in a small copyable RelaxedAtomicPointer so Node keeps its defaulted copy constructor and move assignment. No ordering guarantees are added: the race is on one word, and both writers store the same value. Node.cpp reads the owner through getOwner() instead of the field.

Changelog:
[General][Fixed] - Make reads and writes of a Yoga node's owner atomic, fixing a data race when a node shared between trees is cloned on one thread and laid out on another

Test Plan

  • ./unit_tests Debug: 889 tests pass (googletest needed -Wno-character-conversion with Xcode 27.2's clang, unrelated to this change).
  • react-native-reanimated runtime tests on an iOS simulator with ThreadSanitizer, React Native 0.88.0 built from source: without the change the YGNodeGetOwner race is reported in every run; with an equivalent change applied to the React Native copy of Yoga (relaxed atomic load and store of owner_), two full runs of 621 tests produced no report for it.

A Yoga node shared between two trees can have its owner read by a layout
pass on one thread while a clone of its previous owner on another thread
rewrites it. owner_ was a plain pointer, so that is a data race. Loads and
stores of the owner now use std::atomic with relaxed ordering, through a
small copyable wrapper so Node keeps its defaulted copy operations.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed 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.

1 participant