Skip to content

Clear RuntimeScheduler rendering updates on Scheduler destruction#169

Open
delekta wants to merge 3 commits into0.81.4-discordfrom
delekta/clear-runtime-scheduler-queue-on-scheduler-destructor
Open

Clear RuntimeScheduler rendering updates on Scheduler destruction#169
delekta wants to merge 3 commits into0.81.4-discordfrom
delekta/clear-runtime-scheduler-queue-on-scheduler-destructor

Conversation

@delekta
Copy link
Copy Markdown

@delekta delekta commented Apr 24, 2026

asana ticket

Fix use-after-free crash in Scheduler::uiManagerDidDispatchCommand / uiManagerDidFinishTransaction

When Scheduler is destroyed on the native thread, RuntimeScheduler_Modern's pending rendering-update queue can still hold lambdas that captured SchedulerDelegate* by value. Those lambdas fire later on the JS thread via updateRendering() and dereference the already-destroyed delegate — crashing with EXC_BAD_ACCESS (Sentry #7431302648).

Summary:

Changelog:

Test Plan:

@delekta delekta requested a review from WoLewicki April 24, 2026 14:38
@delekta delekta changed the title Clear RuntimeScheduler queue on scheduler destructor Clear RuntimeScheduler rendering updates on Scheduler destruction Apr 24, 2026
Copy link
Copy Markdown

@WoLewicki WoLewicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good overall and I would consider adding it to RN core too. Still, I would want to investigate if maybe we've got some bug that makes the Scheduler dealloc before RuntimeScheduler does.

// `clear()` blocks until any in-flight `updateRendering` finishes, so it
// is safe to destroy the delegate after this point.
if (runtimeScheduler) {
runtimeScheduler->clear();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move it higher up to where the first if (runtimeScheduler) { is ?

@delekta delekta requested review from pmick April 24, 2026 15:59
@delekta delekta marked this pull request as ready for review April 24, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants