Stop driving the animation backend after Fabric binding teardown#57379
Open
rozele wants to merge 1 commit into
Open
Stop driving the animation backend after Fabric binding teardown#57379rozele wants to merge 1 commit into
rozele wants to merge 1 commit into
Conversation
Summary: WARNING: Generated by Autopilot (alpha) - review carefully, verify the underlying claim before accepting. Agent: React Native Agent | Trajectory: https://www.internalfb.com/intern/devai/devmate/inspector/d5b9a66a-cdcf-42e7-abc9-823520d1bef6/ | SC job: https://www.internalfb.com/intern/sandcastle/instance/18014401277724259/ --- `AnimationBackendChoreographer` registers a self-reposting frame callback with `ReactChoreographer` that keeps invoking `driveAnimationBackend` every frame for the lifetime of the choreographer. `FabricUIManagerBinding.unregister()` tore down the native binding via `uninstallFabricUIManager()` but left that callback running, so a frame that fired after teardown drove a JNI call through the binding's freed native state — a use-after-teardown that can surface as a native crash during React instance reload/teardown while a Fabric (C++ Native Animated) animation is in flight. Pause the choreographer and clear its frame callback in `unregister()` before uninstalling the native binding. A fresh `AnimationBackendChoreographer` is created on every `register()` (it is never reused across instances), and pause/resume are driven by the native animation backend on the next animation, so pausing the now-orphaned choreographer at teardown is safe and does not affect a subsequent re-register. Pausing flips a memory-visible `AtomicBoolean`, so the UI-thread frame callback reliably no-ops even though `unregister()` may run off the UI thread. Changelog: [Android][Fixed] - Stop the Fabric animation frame callback from driving the native binding after teardown, fixing a use-after-teardown native crash Differential Revision: D110150994
|
@rozele has exported this pull request. If you are a Meta employee, you can view the originating Diff in D110150994. |
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:
WARNING: Generated by Autopilot (alpha) - review carefully, verify the underlying claim before accepting.
Agent: React Native Agent | Trajectory: https://www.internalfb.com/intern/devai/devmate/inspector/d5b9a66a-cdcf-42e7-abc9-823520d1bef6/ | SC job: https://www.internalfb.com/intern/sandcastle/instance/18014401277724259/
AnimationBackendChoreographerregisters a self-reposting frame callback withReactChoreographerthat keeps invokingdriveAnimationBackendevery frame for the lifetime of the choreographer.FabricUIManagerBinding.unregister()tore down the native binding viauninstallFabricUIManager()but left that callback running, so a frame that fired after teardown drove a JNI call through the binding's freed native state — a use-after-teardown that can surface as a native crash during React instance reload/teardown while a Fabric (C++ Native Animated) animation is in flight.Pause the choreographer and clear its frame callback in
unregister()before uninstalling the native binding. A freshAnimationBackendChoreographeris created on everyregister()(it is never reused across instances), and pause/resume are driven by the native animation backend on the next animation, so pausing the now-orphaned choreographer at teardown is safe and does not affect a subsequent re-register. Pausing flips a memory-visibleAtomicBoolean, so the UI-thread frame callback reliably no-ops even thoughunregister()may run off the UI thread.Changelog:
[Android][Fixed] - Stop the Fabric animation frame callback from driving the native binding after teardown, fixing a use-after-teardown native crash
Differential Revision: D110150994