Repository navigation
Description
Description
On iOS, the Hermes sampling profiler can crash the app with EXC_BAD_ACCESS in hermes::vm::SamplingProfiler::walkRuntimeStack when it samples while React Native is executing JS synchronously on the main thread.
- React Native registers the runtime for profiling once, on the JS thread:
HermesInstance.cpp→unstable_initializeOnJsThread()→hermesRuntime_.registerForProfiling(). - When a component dispatches with
EventEmitter::experimental_flushSync(React Native's ownVirtualViewdoes), the event beat runs the runtime on the main thread instead (AppleEventBeat::activityDidChange→EventBeat::induce→RuntimeScheduler_Modern::executeNowOnTheSameThread→executeSynchronouslyOnSameThread_CAN_DEADLOCK), while the JS thread is parked on a future. - Nothing in
RuntimeExecutorSyncUIThreadUtils.mmre-registers the profiler for that hand-off. The Hermes contract injsi/hermes-interfaces.hrequires it: "Before using the runtime on another thread, invoke this function again from the new thread to make the sampling profiler target the new thread". - The sampler therefore signals the parked JS thread and walks the runtime's stack from the signal handler while the main thread is mutating it.
Expected: sampling is safe (or skipped) while the runtime is borrowed by the main thread.
Actual: fatal crash.
First seen in a production App Store build, one second after launch, with the sampler enabled by @sentry/react-native 8.33.0 profiling (hermesAPI->enableSamplingProfiler()) and the synchronous dispatch coming from a third-party Fabric component. The linked reproducer needs neither: it uses only React Native 0.88.1, enabling the sampler with the same call and 10 kHz frequency React Native uses for the DevTools Performance panel (HermesRuntimeTargetDelegate.cpp). The same single registerForProfiling() call and the same sync path are still on main as of 2026-12-05.
Steps to reproduce
- Clone the reproducer and install:
cd ReproducerApp && yarn install && cd ios && pod install && cd .. - Run a Release build on an iOS simulator:
yarn react-native run-ios --mode Release - Do nothing. The app scrolls a list of native
VirtualViewrows by itself; each row that becomes visible dispatchesmodeChangewithexperimental_flushSync, running a JS handler on the main thread. - The app crashes about one second after launch.
Results on an iPhone 17 Pro simulator (iOS 26.5 runtime, Xcode 27.2): 6 of 6 launches crashed after ~1.2 s, all in SamplingProfiler::walkRuntimeStack. Control: the same binary with the sampler left off (SIMCTL_CHILD_REPRO_DISABLE_PROFILER=1 xcrun simctl launch booted org.reactjs.native.example.ReproducerApp) was still running after 60 s in 2 of 2 launches.
React Native Version
0.88.1
Affected Platforms
Runtime - iOS
Output of npx @react-native-community/cli info
System:
OS: macOS 27.2.1
CPU: (12) arm64 Apple M2 Max
Memory: 2.31 GB / 32.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 26.14.0
path: /opt/homebrew/bin/node
Yarn:
version: 1.22.22
path: /opt/homebrew/bin/yarn
npm:
version: 12.2.3
path: /opt/homebrew/bin/npm
Watchman: Not Found
Managers:
CocoaPods:
version: 1.17.0
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 27.2
- iOS 27.2
- macOS 27.2
- tvOS 27.2
- visionOS 27.2
- watchOS 27.2
Android SDK: Not Found
IDEs:
Android Studio: 2026.2 AI-262.10968.63.2622.16975389
Xcode:
version: 27.2/27B52
path: /usr/bin/xcodebuild
Languages:
Java:
version: 21.0.13.1
path: /opt/homebrew/opt/openjdk@21/bin/javac
Ruby:
version: 4.0.10
path: /opt/homebrew/bin/ruby
npmPackages:
"@react-native-community/cli": Not Found
react: 19.3.0
react-native: 0.88.1
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: true
newArchEnabled: true
Stacktrace or Logs
From the production crash; the reproducer produces the same three stacks
(see its README for the simulator version).
EXC_BAD_ACCESS (SIGSEGV) KERN_INVALID_ADDRESS at 0x409f402070584
iPhone17,5, iOS 27.2.1 (24B156), App Store build, ~1s after launch
Crashed thread: com.facebook.react.runtime.JavaScript (innermost first)
hermes::vm::SamplingProfiler::walkRuntimeStack
hermes::vm::sampling_profiler::Sampler::walkRuntimeStack
hermes::vm::sampling_profiler::(anonymous namespace)::SamplerPosix::profilingSignalHandler
_sigtramp
_pthread_cond_wait
std::__1::condition_variable::wait
std::__1::__assoc_sub_state::__sub_wait
std::__1::__assoc_sub_state::wait <- JS thread parked on the future
facebook::react::RCTMessageThread::tryFunc
facebook::react::RCTMessageThread::runAsync
+[RCTJSThreadManager runRunLoop]
Thread 0 (main), at the same moment (innermost first)
hermes::vm::Interpreter::interpretFunction
hermes::vm::Runtime::interpretFunctionImpl
hermes::vm::JSFunction::_callImpl
hermes::vm::Callable::executeCall0
hermes::vm::Runtime::drainJobs
facebook::hermes::HermesRuntimeImpl::drainMicrotasks
facebook::react::RuntimeScheduler_Modern::performMicrotaskCheckpoint
facebook::react::RuntimeScheduler_Modern::runEventLoopTick
facebook::react::RuntimeScheduler_Modern::executeNowOnTheSameThread::lambda
facebook::react::coordinatedExecuteSynchronouslyOnSameThread_CAN_DEADLOCK
facebook::react::executeSynchronouslyOnSameThread_CAN_DEADLOCK
facebook::react::RuntimeScheduler_Modern::executeNowOnTheSameThread
facebook::react::EventBeat::induce
facebook::react::AppleEventBeat::activityDidChange
facebook::react::PlatformRunLoopObserver
__CFRunLoopDoObservers
UIApplicationMain
Thread: hermes-sampling-profiler
sem_wait
hermes::vm::sampling_profiler::Sampler::platformSuspendVMAndWalkStack
hermes::vm::sampling_profiler::Sampler::sampleStack
hermes::vm::sampling_profiler::Sampler::sampleStacks
hermes::vm::sampling_profiler::Sampler::timerLoop
MANDATORY Reproducer
https://github.com/sbs44/rn-hermes-sampling-profiler-sync-crash
Screenshots and Videos
None. The thread dumps above and in the reproducer's README are the evidence.
Activity
sbs44 commentedon Dec 5, 2026
Maintainers – I prototyped a fix against the reproducer and I'm happy to open a PR. Let me know your thoughts on the approach:
Hermes already supports moving a runtime between threads:
registerForProfiling()on a runtime that is already registered callsSamplingProfiler::setRuntimeThread(), which retargets the sampler to the calling thread. It takesruntimeDataLock_, the same lock the sampler holds for the whole of each sample, so it waits for any in-flight sample before switching (API/hermes/hermes.cpp,lib/VM/Profiler/SamplingProfilerPosix.cppathermes-v260318099.0.5).So the prototype calls it at both ends of the synchronous hand-off in
RuntimeExecutorSyncUIThreadUtils.mm:runtimeWorkruns;Diff (iOS only, 0.88.1)
Results
Reproducer built with React Native 0.88.1 from source (
RCT_USE_PREBUILT_RNCORE=0), Release, iPhone 17 Pro simulator (iOS 26.5), sampler at 10 kHz:SamplingProfiler::walkRuntimeStackThe profiler keeps working, and it now attributes main-thread JS to the main thread. A 15 s sampled trace from the patched build has 111,992 samples: 98,997 on the JS thread and 12,995 on a second thread. The function that only runs inside the synchronous handler (
churnStack) is on the stack in 12,295 samples, all of them on that second thread.Questions
RuntimeExecutorSyncUIThreadUtilsis engine-agnostic today, and this adds a Hermes interface cast to it (viajsi/hermes-interfaces.h, so no new dependency). Alternatives I can see: a hook onJSRuntimenext tounstable_initializeOnJsThread(), doing it inRuntimeScheduler_Modern::executeNowOnTheSameThread, or fixing it in Hermes (for example, skip the sample when the runtime is not on the registered thread). Preference?platform/cxx/.../RuntimeExecutorSyncUIThreadUtils.cpphas the same shape (the runtime thread parks while the caller uses the runtime), and Android reaches it throughEventEmitterWrapper.cpp'sexperimental_flushSync. Cover Android, too?experimental_flushSyncis marked experimental.