Repository navigation
Conversation
Visual regressionNo visual differences at android: no capture |
…duler is released Rendering updates that Scheduler queues on the JS thread, such as a view command or a finished transaction, call the iOS SchedulerDelegateProxy through a raw pointer. RCTScheduler owned that proxy and freed it in dealloc, which runs on the main thread when RCTSurfacePresenter suspends on UIApplicationWillTerminateNotification. A JS tick that ran between the release and process exit drained a stale update into freed memory. The proxy now holds its RCTSchedulerDelegate weakly, so a late call is a no-op once dealloc clears it, and the proxy itself outlives the updates that captured it: dealloc hands the last reference to a task that schedules a second task on the RuntimeScheduler. A rendering update runs at the end of the tick that queued it, or of the next tick when queued outside one, and a task error discards pending updates together with queued tasks, so none can run after the proxy is released. Fixes react#58601 Signed-off-by: Emma <817422+Pajn@users.noreply.github.com>
Pajn
force-pushed
the
rctscheduler-keep-delegate-proxy-alive
branch
from
December 3, 2026 20:48
9705dc8 to
fb7d363
Compare
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.
Summary:
iOS apps on the New Architecture crash with
EXC_BAD_ACCESSon the JS thread when a view command or transaction is still queued as the renderer's scheduler is released. Production reports in #58601 come mostly from swipe-to-kill, whereRCTSurfacePresentersuspends from itsUIApplicationWillTerminateNotificationobserver. #59754 closed the reload path by keeping the scheduler alive through instance shutdown, but termination releases it directly and is still open onmain.The cause is ownership. Rendering updates queued by
Schedulercapture the iOSSchedulerDelegateProxyby raw pointer, andRCTSchedulerfreed that proxy indeallocon the main thread. This change, confined toRCTScheduler.mm, makes the proxy outlive every update that captured it:RCTSchedulerDelegateweakly, anddeallocclears it, so a late call is a no-op.deallocgives the last reference to the proxy to a task on the runtime scheduler, which schedules a second task that holds it. A rendering update runs at the end of the tick that queued it, or of the next tick when it was queued outside one. A task error discards pending updates together with queued tasks. So by the time the second task runs, every update that captured the proxy has run or been dropped.The release now happens on the JS thread, after the queued updates:
Nothing is locked per update, no flag is checked, and the main thread never waits on the JS thread. Because the fix is in
dealloc, it covers every way the scheduler is released, not only termination. Android is unaffected:FabricUIManagerBindingis the delegate there and outlives theScheduler.One narrow window stays out of scope.
UIManagercalls intoSchedulerthrough a pointer that~Schedulerclears on the main thread, so a view command already past that null check on the JS thread could still reach aSchedulerbeing destroyed. It is a few instructions wide and has not shown up in any reproduction.Fixes #58601
Changelog:
[IOS] [FIXED] - Fix a crash when a queued view command or transaction runs after the renderer scheduler is released, such as when the app is terminated
Test Plan:
RCTSchedulerTestsbuilds a realRCTScheduleron a Hermes runtime with a test-controlled JS queue. It dispatches a view command, so a rendering update captures the delegate proxy, releases the scheduler, then runs the next event loop tick.testQueuedCommandIsDroppedAfterSchedulerIsReleasedfails:RCTSchedulerTestscases and the existingAppleEventBeatTestspass under Address Sanitizer and UBSan.The
React-RCTFabrictest spec isn't part of RNTester's pods, so these ran with:testspecs => ['Tests']added to theReact-RCTFabricpod and the spec's sources limited toTests/Fabric. Outside that folder,RCTSelectableParagraphComponentViewTests.mmdoes not compile in the CocoaPods build:The same change, applied to earlier releases, was measured in the issue:
UIApplicationWillTerminateNotificationwithout exiting: 40 crashes in 40 runs before, none in 100 after.Merge Danger:
Door: two-way. The change is one file plus a test and reverts cleanly.
Blast Radius: iOS renderer. A mistake here would show up as missed or late view commands and transactions on iOS, or a leaked proxy per released scheduler if the runtime scheduler never runs again, for example when the process exits.