Skip to content

Prevent deferred scheduler callbacks from using destroyed delegates - #60181

Open
cipolleschi wants to merge 1 commit into
react:mainfrom
cipolleschi:export-D129211700
Open

cipolleschi wants to merge 1 commit into
react:mainfrom
cipolleschi:export-D129211700

Conversation

@cipolleschi

Copy link
Copy Markdown
Contributor

Summary:
Prevent deferred renderer callbacks from accessing a destroyed scheduler delegate during presenter suspension and app termination.

Capture a delegate generation for queued commands, transactions and React revision merges. Invalidate that generation when the delegate changes or the scheduler is destroyed, so pending callbacks do not call a detached delegate.

Cancellation is not a teardown barrier. A callback can pass the invalidation check while another thread starts teardown. Give each generation shared ownership of the iOS delegate proxy, and replace the proxy's unretained scheduler pointer with a zeroing weak reference. Forwarding acquires a strong scheduler local for the duration of the call, or does nothing if teardown has already begun. Queued callbacks retain the proxy, not the Objective-C scheduler.

During app termination, retain the scheduler while stopping surfaces and removing its layout-animation observer on main. This makes a later last release from an in-flight callback safe from that observer's main-thread callout. Keep the existing instance-invalidation ordering: stop the observer on main and release the scheduler before the runtime in JS cleanup.

The raw-pointer constructor remains available. Its callers remain responsible for the lifetime of already executing delegate calls. Synchronous transactions continue forwarding to a replacement delegate.

Changelog:
[iOS][Fixed] - Prevent queued renderer callbacks from accessing destroyed scheduler delegates during teardown

Differential Revision: D129211700

Summary:
Prevent deferred renderer callbacks from accessing a destroyed scheduler delegate during presenter suspension and app termination.

Capture a delegate generation for queued commands, transactions and React revision merges. Invalidate that generation when the delegate changes or the scheduler is destroyed, so pending callbacks do not call a detached delegate.

Cancellation is not a teardown barrier. A callback can pass the invalidation check while another thread starts teardown. Give each generation shared ownership of the iOS delegate proxy, and replace the proxy's unretained scheduler pointer with a zeroing weak reference. Forwarding acquires a strong scheduler local for the duration of the call, or does nothing if teardown has already begun. Queued callbacks retain the proxy, not the Objective-C scheduler.

During app termination, retain the scheduler while stopping surfaces and removing its layout-animation observer on main. This makes a later last release from an in-flight callback safe from that observer's main-thread callout. Keep the existing instance-invalidation ordering: stop the observer on main and release the scheduler before the runtime in JS cleanup.

The raw-pointer constructor remains available. Its callers remain responsible for the lifetime of already executing delegate calls. Synchronous transactions continue forwarding to a replacement delegate.

Changelog:
[iOS][Fixed] - Prevent queued renderer callbacks from accessing destroyed scheduler delegates during teardown

Differential Revision: D129211700
@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 20, 2026
@meta-codesync

meta-codesync Bot commented Nov 20, 2026

Copy link
Copy Markdown

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

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 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 Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant