Skip to content

Fix render callback start/stop race in C++ NativeAnimated#57270

Open
bartlomiejbloniarz wants to merge 1 commit into
mainfrom
export-D109009181
Open

Fix render callback start/stop race in C++ NativeAnimated#57270
bartlomiejbloniarz wants to merge 1 commit into
mainfrom
export-D109009181

Conversation

@bartlomiejbloniarz

Copy link
Copy Markdown
Contributor

Summary:
The C++ NativeAnimated manager coordinated its render-callback start/stop
through an atomic flag, but registered/unregistered the callback and tracked its
id outside that atomic. When start (JS thread) and stop (UI thread) ran
concurrently, a stop could act on a stale id and miss the just-registered
callback, leaving it orphaned. Orphaned callbacks are never removed and run on
every frame, accumulating over time.

Coordinate the shared animation backend path through a single atomic callback id
(0 means "not started"): start registers then publishes the id with a
compare-exchange, undoing the registration if it lost the race; stop atomically
takes the id and stops exactly that callback. Reserve backend callback id 0 so
it can serve as the sentinel.

Changelog: [General][Fixed] - Fix a race in the C++ Animated render-callback lifecycle that could leave stale callbacks running on every frame

Differential Revision: D109009181

Summary:
The C++ NativeAnimated manager coordinated its render-callback start/stop
through an atomic flag, but registered/unregistered the callback and tracked its
id outside that atomic. When start (JS thread) and stop (UI thread) ran
concurrently, a stop could act on a stale id and miss the just-registered
callback, leaving it orphaned. Orphaned callbacks are never removed and run on
every frame, accumulating over time.

Coordinate the shared animation backend path through a single atomic callback id
(0 means "not started"): start registers then publishes the id with a
compare-exchange, undoing the registration if it lost the race; stop atomically
takes the id and stops exactly that callback. Reserve backend callback id 0 so
it can serve as the sentinel.

Changelog: [General][Fixed] - Fix a race in the C++ Animated render-callback lifecycle that could leave stale callbacks running on every frame

Differential Revision: D109009181
@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 Jun 18, 2026
@facebook-github-tools facebook-github-tools Bot added p: Software Mansion Partner: Software Mansion Partner p: Facebook Partner: Facebook labels Jun 18, 2026
@meta-codesync

meta-codesync Bot commented Jun 18, 2026

Copy link
Copy Markdown

@bartlomiejbloniarz has exported this pull request. If you are a Meta employee, you can view the originating Diff in D109009181.

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. meta-exported p: Facebook Partner: Facebook p: Software Mansion Partner: Software Mansion Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant