Skip to content

Clear RuntimeScheduler rendering updates on Scheduler destruction#169

Merged
delekta merged 3 commits into0.81.4-discordfrom
delekta/clear-runtime-scheduler-queue-on-scheduler-destructor
Apr 27, 2026
Merged

Clear RuntimeScheduler rendering updates on Scheduler destruction#169
delekta merged 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 ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

discussed offline

@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
@delekta delekta merged commit f01c9d8 into 0.81.4-discord Apr 27, 2026
59 of 72 checks passed
@delekta delekta deleted the delekta/clear-runtime-scheduler-queue-on-scheduler-destructor branch April 27, 2026 10:26
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