Skip to content

iOS: EXC_BAD_ACCESS in RuntimeScheduler_Modern::runEventLoopTick on reload — queued rendering update calls the freed SchedulerDelegate #60324

Backlog

Description

@yspreen

Description

On iOS (New Architecture, bridgeless), an app crashes with EXC_BAD_ACCESS on the old instance's JS thread when it reloads its React instance while that instance is still committing UI updates. In our case the reload is expo-updates' Updates.reloadAsync() right after an update is downloaded at launch, while the app is still mounting its first screens. Anything that tears down RCTHost/RCTInstance this way is affected (dev reload, OTA reload).

Root cause. Scheduler queues rendering updates on RuntimeScheduler_Modern that capture the SchedulerDelegate as a raw pointer:

  • Scheduler::uiManagerDidFinishTransaction → delegate->schedulerShouldRenderTransactions(...)
  • Scheduler::uiManagerDidDispatchCommand → delegate->schedulerDidDispatchCommand(...)
  • Scheduler::uiManagerDidFinishReactCommit → delegate->schedulerShouldMergeReactRevision(...)

On iOS the delegate is SchedulerDelegateProxy, owned by RCTScheduler (std::unique_ptr<SchedulerDelegateProxy> _delegateProxy). During teardown -[RCTScheduler dealloc] calls _scheduler->setDelegate(nullptr) on the main thread and then frees the proxy. Meanwhile the old instance's JS thread can still be in runEventLoopTick. At the end of the tick, updateRendering() drains pendingRenderingUpdates_, and the lambda calls a virtual method through the freed proxy.

This is the window that #58138 (removing enableSchedulerDelegateInvalidation) describes as still open: a delegate detached with no error never reaches handleTaskError, so nothing clears the queue. SchedulerDelegateInvalidationTest's DelegateDetachedWithoutError_PendingRenderingUpdateCallsStaleDelegate pins it. This issue shows that window being hit in production, through a plain reload with no JS error.

Steps to reproduce

The race is timing dependent, so there is no deterministic repro in an app. The conditions:

  1. iOS, New Architecture (bridgeless), RN 0.88.1. The code is unchanged on main.
  2. Have the app commit continuously (e.g. mount a large tree and load data) while calling a reload: Updates.reloadAsync() from expo-updates, or DevSettings.reload().
  3. Sometimes the old instance's JS thread crashes as below.

Deterministic repro at the unit level: in SchedulerDelegateInvalidationTest, enqueue a transaction, call setDelegate(nullptr), then drain one tick. The queued lambda still calls the detached delegate (see the existing Test 3).

React Native Version

0.88.1

Affected Platforms

Runtime - iOS

Areas

Fabric - The New Renderer, Bridgeless - The New Initialization Flow

Output of npx @react-native-community/cli info

React Native 0.88.1, Expo SDK 58, Hermes, New Architecture (bridgeless). Release build from the App Store, iOS 27.2.1, iPhone 11 Pro (iPhone12,3).

Stacktrace or Logs

EXC_BAD_ACCESS / SIGSEGV: KERN_INVALID_ADDRESS at 0x9b3e6f6895d8472d
x9 = 0x9b3e6f6895d84725  (fault address = x9 + 8: a vtable slot loaded through freed memory)

Thread 11 Crashed: com.facebook.react.runtime.JavaScript   (old instance)
0  React  std::__1::__function::__func<...>::operator()              <- queued rendering update lambda
1  React  facebook::react::RuntimeScheduler_Modern::runEventLoopTick
2  React  facebook::react::RuntimeScheduler_Modern::runEventLoop
3  React  std::__1::__function::__func<...>::operator()
4  React  facebook::react::tryAndReturnError
5  React  std::__1::__function::__func<...>::operator()
6  React  facebook::react::RCTMessageThread::runAsync
7  CoreFoundation  __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__
...
10 React  +[RCTJSThreadManager runRunLoop]

Thread 22: (new instance, already running JS)
0  hermesvm  hermes::vm::Interpreter::interpretFunction
...
   React  facebook::react::Task::execute
   React  facebook::react::RuntimeScheduler_Modern::executeTask
   React  facebook::react::RuntimeScheduler_Modern::runEventLoopTick
   ...
   React  +[RCTJSThreadManager runRunLoop]

Two React instances were alive at the time of the crash: two JS threads running RCTJSThreadManager runRunLoop, and two sets of Hermes HadesGC and SerialExecutor threads. The crash came about 2 s after app start, right after the app called reloadAsync().

MANDATORY Reproducer

The race can't be shown deterministically in an app (see Steps). The unit-level reproduction is the existing SchedulerDelegateInvalidationTest (Test 3). The linked PR turns it into a regression test and adds tests for a detach that happens while a queued update is calling the delegate.

Screenshots and Videos

No response

Activity

  1. added
    Needs: Repro
    on Nov 27, 2026
  2. react-native-bot commented on Nov 27, 2026

    @react-native-bot
    Collaborator

    Warning

    Missing reproducer: We could not detect a reproducible example in your issue report. Reproducers are mandatory and we can accept only one of those as a valid reproducer:


    You can read more about about it on our website: How to report a bug.

  3. added 2 commits that reference this issue on Nov 27, 2026
    3206413
    3d7dec3
  4. yspreen commented on Nov 27, 2026

    @yspreen
    Author

    About the reproducer: this is a teardown race, and I don't have an app that hits it on demand. I tried a fresh project from the reproducer template on 0.88.1, Release build on an iOS 27.2 simulator: a grid that re-renders every frame, scrollTo commands from inside and outside React's lifecycle, and a native reload (RCTTriggerReloadCommandListeners) every 50-400 ms. It survived about 4,600 reloads, including 1,175 with MallocScribble=1. The trace in the report comes from a production app (one occurrence so far, iPhone 11 Pro, iOS 27.2.1): the crash came 2 s after launch, right after expo-updates' reloadAsync().

    The reproduction that is deterministic is at the unit level, and it is already in the repo: SchedulerDelegateInvalidationTest's DelegateDetachedWithoutError_PendingRenderingUpdateCallsStaleDelegate (added with #58138). It shows a queued rendering update calling a detached delegate when no JS error is involved. On iOS, -[RCTScheduler dealloc] frees that delegate (SchedulerDelegateProxy) right after setDelegate(nullptr), which turns that call into the use-after-free in the stack trace above.

    #60325 fixes it and turns that test into a regression test. Its test plan shows the tests failing without the fix.

  5. added
    Needs: Attention
    and removed on Nov 27, 2026
  6. nbushak commented on Dec 1, 2026

    @nbushak

    We hit this too on RN 0.88.1 / Expo SDK 58 (bridgeless, Hermes), and our app reproduces it on demand, though we also don't have a minimal project:

    • iOS 27.2 simulator, Debug build.
    • A chat screen streaming a reply into a list (a commit every few frames), with a JS reload (DevSettings.reload()) every 2–4 seconds.
    • Without a fix it crashed on the 9th reload in our run, on the old instance's JS thread in a queued rendering-update lambda, as in the report.

    We're applying this guard (essentially #56680 with a token per delegate), through patch-package with ios.buildReactNativeFromSource so it compiles:

    --- a/ReactCommon/react/renderer/scheduler/Scheduler.h
    +++ b/ReactCommon/react/renderer/scheduler/Scheduler.h
       SchedulerDelegate *delegate_;
    +  std::shared_ptr<std::atomic<bool>> delegateInvalidated_;
       SharedComponentDescriptorRegistry componentDescriptorRegistry_;
    --- a/ReactCommon/react/renderer/scheduler/Scheduler.cpp
    +++ b/ReactCommon/react/renderer/scheduler/Scheduler.cpp
    @@ Scheduler::Scheduler(
    -    : runtimeExecutor_(schedulerToolbox.runtimeExecutor),
    +    : delegateInvalidated_(std::make_shared<std::atomic<bool>>(false)),
    +      runtimeExecutor_(schedulerToolbox.runtimeExecutor),
    @@ Scheduler::~Scheduler() {
    +  *delegateInvalidated_ = true;
    @@ void Scheduler::setDelegate(SchedulerDelegate* delegate) {
    +  if (delegate_ != delegate) {
    +    *delegateInvalidated_ = true;
    +    delegateInvalidated_ = std::make_shared<std::atomic<bool>>(false);
    +  }
       delegate_ = delegate;
    @@ void Scheduler::uiManagerDidFinishTransaction(
               [delegate = delegate_,
    +           invalidated = delegateInvalidated_,
                mountingCoordinator = std::move(mountingCoordinator)]() {
    +            if (*invalidated) {
    +              return;
    +            }
                 delegate->schedulerShouldRenderTransactions(mountingCoordinator);
    @@ void Scheduler::uiManagerDidDispatchCommand(
             [delegate = delegate_,
    +         invalidated = delegateInvalidated_,
              shadowView = std::move(shadowView),
              commandName,
              args]() {
    +          if (*invalidated) {
    +            return;
    +          }
               delegate->schedulerDidDispatchCommand(shadowView, commandName, args);

    With it, 40 reloads during streaming (29 logged Scheduler teardowns) didn't crash. In 0.88.1 the uiManagerDidFinishReactCommit update doesn't capture the delegate: it reads delegate_ when it runs, so setDelegate(nullptr) already covers it.

    This narrows the race but doesn't close it: the old JS thread can pass the flag check just before the main thread frees SchedulerDelegateProxy. A complete fix probably needs the queued work to keep the delegate alive (or check a weak owner), or teardown to wait for the old JS thread to drain.

  7. nazmiaydogdu commented on Dec 4, 2026

    @nazmiaydogdu

    We get the same crash when iOS terminates the app (RN 0.88.1, bridgeless). RCTSurfacePresenter._applicationWillTerminate calls suspend, which drops the delegate with no error: the open window described in #58138.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: AttentionNeeds: Repro

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions