react-native: Reloading a dev app rapidly crashes the app

Description

When repeatedly reloading the app pressing “r” in the metro bundler the app crashes

Steps to reproduce

  1. Run the example application on iOS [Note: I think this should be reproducible with the react-native example app] 1.1 cd ReproducerApp 1.2 yarn 1.3 yarn pods 1.4 Open the iOS project and build xed ios
  2. Make sure its on new arch & bridgleless
  3. In the metro bundler spam the “r” button for reload (you might need to spam it many many times)
  4. You’ll get a crash

Note: The effect is amplified in a real world app with more elements.

React Native Version

0.74.1

Affected Platforms

Runtime - iOS

Areas

Fabric - The New Renderer

Output of npx react-native info

Note: This command is broken and doesn't work asof RN 0.74.1

OS: macOS Sonoma 14.4.1
Node Version: v20.13.0
react-native version: 0.74.1

Stacktrace or Logs

com.facebook.react.runtime.JavaScript (22)
#0	0x00000001048dc304 in facebook::react::Scheduler::uiManagerDidFinishTransaction(std::__1::shared_ptr<facebook::react::MountingCoordinator const>, bool)::$_7::operator()() const at /Users/hannomargelo/Documents/Github/react-native-worklets-core/package/example/node_modules/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp:290
#1	0x00000001048dc2dc in decltype(std::declval<facebook::react::Scheduler::uiManagerDidFinishTransaction(std::__1::shared_ptr<facebook::react::MountingCoordinator const>, bool)::$_7&>()()) std::__1::__invoke[abi:ue170006]<facebook::react::Scheduler::uiManagerDidFinishTransaction(std::__1::shared_ptr<facebook::react::MountingCoordinator const>, bool)::$_7&>(facebook::react::Scheduler::uiManagerDidFinishTransaction(std::__1::shared_ptr<facebook::react::MountingCoordinator const>, bool)::$_7&) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__type_traits/invoke.h:340
#2	0x00000001048dc294 in void std::__1::__invoke_void_return_wrapper<void, true>::__call[abi:ue170006]<facebook::react::Scheduler::uiManagerDidFinishTransaction(std::__1::shared_ptr<facebook::react::MountingCoordinator const>, bool)::$_7&>(facebook::react::Scheduler::uiManagerDidFinishTransaction(std::__1::shared_ptr<facebook::react::MountingCoordinator const>, bool)::$_7&) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__type_traits/invoke.h:415
#3	0x00000001048dc270 in std::__1::__function::__alloc_func<facebook::react::Scheduler::uiManagerDidFinishTransaction(std::__1::shared_ptr<facebook::react::MountingCoordinator const>, bool)::$_7, std::__1::allocator<facebook::react::Scheduler::uiManagerDidFinishTransaction(std::__1::shared_ptr<facebook::react::MountingCoordinator const>, bool)::$_7>, void ()>::operator()[abi:ue170006]() at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__functional/function.h:193
#4	0x00000001048daf84 in std::__1::__function::__func<facebook::react::Scheduler::uiManagerDidFinishTransaction(std::__1::shared_ptr<facebook::react::MountingCoordinator const>, bool)::$_7, std::__1::allocator<facebook::react::Scheduler::uiManagerDidFinishTransaction(std::__1::shared_ptr<facebook::react::MountingCoordinator const>, bool)::$_7>, void ()>::operator()() at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__functional/function.h:364
#5	0x0000000104613a48 in std::__1::__function::__value_func<void ()>::operator()[abi:ue170006]() const at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__functional/function.h:518
#6	0x0000000104613968 in std::__1::function<void ()>::operator()() const at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__functional/function.h:1169
#7	0x0000000104d8f58c in facebook::react::RuntimeScheduler_Modern::updateRendering() at /Users/hannomargelo/Documents/Github/react-native-worklets-core/package/example/node_modules/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Modern.cpp:321
#8	0x0000000104d8edb4 in facebook::react::RuntimeScheduler_Modern::executeTask(facebook::jsi::Runtime&, std::__1::shared_ptr<facebook::react::Task> const&, std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l>>>) at /Users/hannomargelo/Documents/Github/react-native-worklets-core/package/example/node_modules/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Modern.cpp:306
#9	0x0000000104d8e868 in facebook::react::RuntimeScheduler_Modern::startWorkLoop(facebook::jsi::Runtime&, bool) at /Users/hannomargelo/Documents/Github/react-native-worklets-core/package/example/node_modules/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Modern.cpp:245
#10	0x0000000104d978cc in facebook::react::RuntimeScheduler_Modern::scheduleWorkLoop()::$_1::operator()(facebook::jsi::Runtime&) const at /Users/hannomargelo/Documents/Github/react-native-worklets-core/package/example/node_modules/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Modern.cpp:224
#11	0x0000000104d97894 in decltype(std::declval<facebook::react::RuntimeScheduler_Modern::scheduleWorkLoop()::$_1&>()(std::declval<facebook::jsi::Runtime&>())) std::__1::__invoke[abi:ue170006]<facebook::react::RuntimeScheduler_Modern::scheduleWorkLoop()::$_1&, facebook::jsi::Runtime&>(facebook::react::RuntimeScheduler_Modern::scheduleWorkLoop()::$_1&, facebook::jsi::Runtime&) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__type_traits/invoke.h:340
#12	0x0000000104d97844 in void std::__1::__invoke_void_return_wrapper<void, true>::__call[abi:ue170006]<facebook::react::RuntimeScheduler_Modern::scheduleWorkLoop()::$_1&, facebook::jsi::Runtime&>(facebook::react::RuntimeScheduler_Modern::scheduleWorkLoop()::$_1&, facebook::jsi::Runtime&) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__type_traits/invoke.h:415
#13	0x0000000104d97818 in std::__1::__function::__alloc_func<facebook::react::RuntimeScheduler_Modern::scheduleWorkLoop()::$_1, std::__1::allocator<facebook::react::RuntimeScheduler_Modern::scheduleWorkLoop()::$_1>, void (facebook::jsi::Runtime&)>::operator()[abi:ue170006](facebook::jsi::Runtime&) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__functional/function.h:193
#14	0x0000000104d96694 in std::__1::__function::__func<facebook::react::RuntimeScheduler_Modern::scheduleWorkLoop()::$_1, std::__1::allocator<facebook::react::RuntimeScheduler_Modern::scheduleWorkLoop()::$_1>, void (facebook::jsi::Runtime&)>::operator()(facebook::jsi::Runtime&) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__functional/function.h:364
#15	0x0000000104684000 in std::__1::__function::__value_func<void (facebook::jsi::Runtime&)>::operator()[abi:ue170006](facebook::jsi::Runtime&) const at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__functional/function.h:518
#16	0x000000010468243c in std::__1::function<void (facebook::jsi::Runtime&)>::operator()(facebook::jsi::Runtime&) const at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__functional/function.h:1169
#17	0x0000000104c32284 in facebook::react::ReactInstance::ReactInstance(std::__1::unique_ptr<facebook::react::JSRuntime, std::__1::default_delete<facebook::react::JSRuntime>>, std::__1::shared_ptr<facebook::react::MessageQueueThread>, std::__1::shared_ptr<facebook::react::TimerManager>, std::__1::function<void (facebook::react::MapBuffer)>, facebook::react::jsinspector_modern::PageTarget*)::$_0::operator()(std::__1::function<void (facebook::jsi::Runtime&)>&&) const::'lambda'()::operator()() const at /Users/hannomargelo/Documents/Github/react-native-worklets-core/package/example/node_modules/react-native/ReactCommon/react/runtime/ReactInstance.cpp:70
#18	0x0000000104c32208 in decltype(std::declval<facebook::react::ReactInstance::ReactInstance(std::__1::unique_ptr<facebook::react::JSRuntime, std::__1::default_delete<facebook::react::JSRuntime>>, std::__1::shared_ptr<facebook::react::MessageQueueThread>, std::__1::shared_ptr<facebook::react::TimerManager>, std::__1::function<void (facebook::react::MapBuffer)>, facebook::react::jsinspector_modern::PageTarget*)::$_0::operator()(std::__1::function<void (facebook::jsi::Runtime&)>&&) const::'lambda'()&>()()) std::__1::__invoke[abi:ue170006]<facebook::react::ReactInstance::ReactInstance(std::__1::unique_ptr<facebook::react::JSRuntime, std::__1::default_delete<facebook::react::JSRuntime>>, std::__1::shared_ptr<facebook::react::MessageQueueThread>, std::__1::shared_ptr<facebook::react::TimerManager>, std::__1::function<void (facebook::react::MapBuffer)>, facebook::react::jsinspector_modern::PageTarget*)::$_0::operator()(std::__1::function<void (facebook::jsi::Runtime&)>&&) const::'lambda'()&>(facebook::react::ReactInstance::ReactInstance(std::__1::unique_ptr<facebook::react::JSRuntime, std::__1::default_delete<facebook::react::JSRuntime>>, std::__1::shared_ptr<facebook::react::MessageQueueThread>, std::__1::shared_ptr<facebook::react::TimerManager>, std::__1::function<void (facebook::react::MapBuffer)>, facebook::react::jsinspector_modern::PageTarget*)::$_0::operator()(std::__1::function<void (facebook::jsi::Runtime&)>&&) const::'lambda'()&) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__type_traits/invoke.h:340
#19	0x0000000104c321c0 in void std::__1::__invoke_void_return_wrapper<void, true>::__call[abi:ue170006]<facebook::react::ReactInstance::ReactInstance(std::__1::unique_ptr<facebook::react::JSRuntime, std::__1::default_delete<facebook::react::JSRuntime>>, std::__1::shared_ptr<facebook::react::MessageQueueThread>, std::__1::shared_ptr<facebook::react::TimerManager>, std::__1::function<void (facebook::react::MapBuffer)>, facebook::react::jsinspector_modern::PageTarget*)::$_0::operator()(std::__1::function<void (facebook::jsi::Runtime&)>&&) const::'lambda'()&>(facebook::react::ReactInstance::ReactInstance(std::__1::unique_ptr<facebook::react::JSRuntime, std::__1::default_delete<facebook::react::JSRuntime>>, std::__1::shared_ptr<facebook::react::MessageQueueThread>, std::__1::shared_ptr<facebook::react::TimerManager>, std::__1::function<void (facebook::react::MapBuffer)>, facebook::react::jsinspector_modern::PageTarget*)::$_0::operator()(std::__1::function<void (facebook::jsi::Runtime&)>&&) const::'lambda'()&) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__type_traits/invoke.h:415
#20	0x0000000104c3219c in std::__1::__function::__alloc_func<facebook::react::ReactInstance::ReactInstance(std::__1::unique_ptr<facebook::react::JSRuntime, std::__1::default_delete<facebook::react::JSRuntime>>, std::__1::shared_ptr<facebook::react::MessageQueueThread>, std::__1::shared_ptr<facebook::react::TimerManager>, std::__1::function<void (facebook::react::MapBuffer)>, facebook::react::jsinspector_modern::PageTarget*)::$_0::operator()(std::__1::function<void (facebook::jsi::Runtime&)>&&) const::'lambda'(), std::__1::allocator<facebook::react::ReactInstance::ReactInstance(std::__1::unique_ptr<facebook::react::JSRuntime, std::__1::default_delete<facebook::react::JSRuntime>>, std::__1::shared_ptr<facebook::react::MessageQueueThread>, std::__1::shared_ptr<facebook::react::TimerManager>, std::__1::function<void (facebook::react::MapBuffer)>, facebook::react::jsinspector_modern::PageTarget*)::$_0::operator()(std::__1::function<void (facebook::jsi::Runtime&)>&&) const::'lambda'()>, void ()>::operator()[abi:ue170006]() at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__functional/function.h:193
#21	0x0000000104c30ef4 in std::__1::__function::__func<facebook::react::ReactInstance::ReactInstance(std::__1::unique_ptr<facebook::react::JSRuntime, std::__1::default_delete<facebook::react::JSRuntime>>, std::__1::shared_ptr<facebook::react::MessageQueueThread>, std::__1::shared_ptr<facebook::react::TimerManager>, std::__1::function<void (facebook::react::MapBuffer)>, facebook::react::jsinspector_modern::PageTarget*)::$_0::operator()(std::__1::function<void (facebook::jsi::Runtime&)>&&) const::'lambda'(), std::__1::allocator<facebook::react::ReactInstance::ReactInstance(std::__1::unique_ptr<facebook::react::JSRuntime, std::__1::default_delete<facebook::react::JSRuntime>>, std::__1::shared_ptr<facebook::react::MessageQueueThread>, std::__1::shared_ptr<facebook::react::TimerManager>, std::__1::function<void (facebook::react::MapBuffer)>, facebook::react::jsinspector_modern::PageTarget*)::$_0::operator()(std::__1::function<void (facebook::jsi::Runtime&)>&&) const::'lambda'()>, void ()>::operator()() at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__functional/function.h:364
#22	0x0000000104613a48 in std::__1::__function::__value_func<void ()>::operator()[abi:ue170006]() const at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__functional/function.h:518
#23	0x0000000104613968 in std::__1::function<void ()>::operator()() const at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__functional/function.h:1169
#24	0x0000000104664ad4 in facebook::react::tryAndReturnError(std::__1::function<void ()> const&) at /Users/hannomargelo/Documents/Github/react-native-worklets-core/package/example/node_modules/react-native/React/CxxModule/RCTCxxUtils.mm:73
#25	0x000000010468cfb0 in facebook::react::RCTMessageThread::tryFunc(std::__1::function<void ()> const&) at /Users/hannomargelo/Documents/Github/react-native-worklets-core/package/example/node_modules/react-native/React/CxxBridge/RCTMessageThread.mm:68
#26	0x0000000104691e40 in facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_1::operator()() const at /Users/hannomargelo/Documents/Github/react-native-worklets-core/package/example/node_modules/react-native/React/CxxBridge/RCTMessageThread.mm:81
#27	0x0000000104691de4 in decltype(std::declval<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_1&>()()) std::__1::__invoke[abi:ue170006]<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_1&>(facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_1&) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__type_traits/invoke.h:340
#28	0x0000000104691d9c in void std::__1::__invoke_void_return_wrapper<void, true>::__call[abi:ue170006]<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_1&>(facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_1&) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__type_traits/invoke.h:415
#29	0x0000000104691d78 in std::__1::__function::__alloc_func<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_1, std::__1::allocator<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_1>, void ()>::operator()[abi:ue170006]() at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__functional/function.h:193
#30	0x0000000104690a88 in std::__1::__function::__func<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_1, std::__1::allocator<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_1>, void ()>::operator()() at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__functional/function.h:364
#31	0x0000000104613a48 in std::__1::__function::__value_func<void ()>::operator()[abi:ue170006]() const at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__functional/function.h:518
#32	0x0000000104613968 in std::__1::function<void ()>::operator()() const at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.4.sdk/usr/include/c++/v1/__functional/function.h:1169
#33	0x000000010468cd74 in invocation function for block in facebook::react::RCTMessageThread::runAsync(std::__1::function<void ()>) at /Users/hannomargelo/Documents/Github/react-native-worklets-core/package/example/node_modules/react-native/React/CxxBridge/RCTMessageThread.mm:44
#34	0x000000018040ec50 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ ()
#35	0x000000018040e398 in __CFRunLoopDoBlocks ()
#36	0x0000000180409264 in __CFRunLoopRun ()
#37	0x0000000180408514 in CFRunLoopRunSpecific ()
#38	0x0000000104c1a228 in +[RCTJSThreadManager runRunLoop] at /Users/hannomargelo/Documents/Github/react-native-worklets-core/package/example/node_modules/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTJSThreadManager.mm:102
#39	0x0000000180e10be4 in __NSThread__start__ ()
#40	0x0000000106fab414 in _pthread_start ()

Reproducer

https://github.com/hannojg/crash-on-reload

Screenshots and Videos

https://github.com/facebook/react-native/assets/16821682/c3f66127-6ddd-4f76-bfeb-72ec87cfdfdc

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 15 (13 by maintainers)

Commits related to this issue

Most upvoted comments

I like the debounce solution. We can isolate it in a single location in the codebase and mitigate the issue to the point that it does not present itself anymore.

I upgraded to Xcode 15.4 and tested with iOS 17.5 and I am still able to reproduce it 😅

Screenshot 2024-06-05 at 08 24 27

uhm, you sure you pushed? I only see these commits: Screenshot 2024-06-03 at 13 28 11

Perhaps you committed but not pushed to remote?

I just tried with the reproducer (which spins up a new app with 0.74.1) and can’t repro it… 😕

I created a new app with 0.74.1 to reproduce your same scenario and environment. I can’t repro the issue there either.

https://github.com/facebook/react-native/assets/11162307/ee96e177-02ba-4da4-b05c-7df0a417976e

@hannojg Thanks for the issue. I just tried myself with an app on 0.74.1 and I could not reproduce the issue:

https://github.com/facebook/react-native/assets/11162307/7a518ccb-57dd-4e80-9b51-fca3eff0030d