Repository navigation
Conversation
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
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.
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 twoShadowTree::commitcalls overlap: the clone andlayoutIfNeededrun outside the revision mutex,YogaLayoutableShadowNode::updateYogaChildrenOwnersIfNeededwrites a sentinel into the owner of shared children, and the other commit reads the owner inNode::cloneChildrenIfNeededandYGNodeGetOwner.owner_is a plainNode*, 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 copyableRelaxedAtomicPointersoNodekeeps 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.cppreads the owner throughgetOwner()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-conversionwith Xcode 27.2's clang, unrelated to this change).YGNodeGetOwnerrace is reported in every run; with an equivalent change applied to the React Native copy of Yoga (relaxed atomic load and store ofowner_), two full runs of 621 tests produced no report for it.