Skip to content

Fix: avoid deadlock by removing requiresMainQueueSetup = true from Mapbox view managers - #3954

Merged
mfazekas merged 1 commit into
rnmapbox:mainfrom
whiteHatCip:defects/app-freezes-randomly
Aug 29, 2025
Merged

mfazekas merged 1 commit into
rnmapbox:mainfrom
whiteHatCip:defects/app-freezes-randomly

Conversation

@whiteHatCip

@whiteHatCip whiteHatCip commented Aug 28, 2025 •

Copy link
Copy Markdown
Contributor

Description

Fixes #3886

Checklist

  • I've read CONTRIBUTING.md
  • I updated the doc/other generated code with running yarn generate in the root folder
  • I have tested the new feature on /example app.
    • In V11 mode/ios
    • In New Architecture mode/ios
    • In V11 mode/android
    • In New Architecture mode/android
  • I added/updated a sample - if a new feature was implemented (/example)

There's no need for a component that reproduces the bug because the bug happens also in the example app.

Since it's happening apparently randomly, I cannot tell the exact steps to reproduce the bug, and to verify whether my proposed solution gets rid of the bug 100% sure, but before I made these changes I was experiencing the app freeze every time I ran the app. After applying these changes, the bug was no more, despite I have to admit that I've been launching, playing with and killing and starting again the app for about 30-40 minutes, hence this is just manual testing and has intrinsic limitations.

Bug Root Cause

Several Mapbox view managers declared:

@objc
override static func requiresMainQueueSetup() -> Bool {
    return true
}

This forces React Native to lazily initialize the TurboModule / view manager on the main thread, synchronously, the first time JS code accesses it.

When this lazy initialization happened while Fabric was already performing a synchronous UI update (e.g. from a native-driven animation), both the JS thread and the main thread ended up waiting on each other:
• The main thread held a shared lock in ComponentDescriptorRegistry while updating props.
• The JS thread tried to resolve the view manager, which called into RCTUnsafeExecuteOnMainQueueSync to initialize the module.
• Result: main waits for JS, JS waits for main → deadlock.

This manifested as the app “freezing” with no crash logs, sometimes seemingly at random.

Probably the reason why @McFly78 could experience less frequent freezes when he reduced the amount children of the Map: less children were racing to be initialized and updated. At least that's my guess.

Fix

All Mapbox view managers that previously returned YES from requiresMainQueueSetup now return NO.

None of these managers actually require synchronous main-thread setup (they don’t touch UIKit at initialization time), so they can be safely initialized off the main thread. This eliminates the main-thread synchronous call and removes the possibility of deadlock.

Outcome

  • No more app freezes during Fabric rendering.
  • Module initialization remains safe and functional.
  • Aligns with React Native’s recommendation: only return true from requiresMainQueueSetup if the module truly depends on UIKit during initialization.

requiresMainQueueSetup, which forces React Native to lazily
initialize the TurboModule on the main thread.

When this initialization happened while Fabric was performing a
synchronous UI update (e.g. from native-driven animations),
the JS thread and main thread could deadlock:

- Main thread held a shared lock in ComponentDescriptorRegistry
  during synchronouslyUpdateViewOnUIThread.
- JS thread attempted to resolve the view manager, triggering
  RCTUnsafeExecuteOnMainQueueSync.
- Both threads waited on each other → freeze.

Since these view managers do not require UIKit access during init,
they can safely return false. This removes the synchronous main-thread
call and eliminates the deadlock condition.
@whiteHatCip
whiteHatCip force-pushed the defects/app-freezes-randomly branch from 1a982c5 to 82e0e2f Compare August 29, 2025 13:05
@whiteHatCip
whiteHatCip temporarily deployed to CI with Mapbox Tokens August 29, 2025 13:23 — with GitHub Actions Inactive
@whiteHatCip
whiteHatCip temporarily deployed to CI with Mapbox Tokens August 29, 2025 13:23 — with GitHub Actions Inactive
@whiteHatCip
whiteHatCip temporarily deployed to CI with Mapbox Tokens August 29, 2025 13:23 — with GitHub Actions Inactive
@whiteHatCip
whiteHatCip temporarily deployed to CI with Mapbox Tokens August 29, 2025 13:23 — with GitHub Actions Inactive
@whiteHatCip
whiteHatCip temporarily deployed to CI with Mapbox Tokens August 29, 2025 13:23 — with GitHub Actions Inactive
@whiteHatCip
whiteHatCip temporarily deployed to CI with Mapbox Tokens August 29, 2025 13:23 — with GitHub Actions Inactive
@whiteHatCip
whiteHatCip temporarily deployed to CI with Mapbox Tokens August 29, 2025 13:23 — with GitHub Actions Inactive
@mfazekas

mfazekas commented Aug 29, 2025 •

Copy link
Copy Markdown
Contributor

@whiteHatCip good catch.

I happen to reproduce the issue, I think the bug is in ReactNative locking mechanism for ComponentDescriptorRegistry. It's holding a lock while calling code that can wait on main thread. That's asking for deadlock. Not using requiresMainQueueSetup is a good workaround, I don't think we need that either.

For me main thread was waiting in
facebook::react::ComponentDescriptorRegistry::findComponentDescriptorByHandle_DO_NOT_USE_THIS_IS_BROKEN

https://github.com/facebook/react-native/blob/8f8d6f06897b3f2667b4cbdfc62875baee114b60/packages/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp#L116-L127

While the js thread was trying to to create a view and first tried to init the manager, which required the main queue, but it hold a lock inside ComponentDescriptorRegistry::add

https://github.com/facebook/react-native/blob/8f8d6f06897b3f2667b4cbdfc62875baee114b60/packages/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp#L31-L51

Also this is somewhat documented in react-native source:

https://github.com/facebook/react-native/blob/7404fb620bb609dddd788bef16fdb9390ef2478b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm#L603-L611

And see also:
react/react-native#53128

com.facebook.react.runtime.JavaScript (10)

#0	0x0000000111c016f6 in __psynch_cvwait ()
#1	0x0000000111d6d302 in _pthread_cond_wait ()
#2	0x000000010981da16 in std::__1::condition_variable::wait ()
#3	0x000000010981ee55 in std::__1::__shared_mutex_base::lock_shared ()
#4	0x000000010d41f925 in std::__1::shared_mutex::lock_shared[abi:de190102] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/shared_mutex:206
#5	0x000000010d41f907 in std::__1::shared_lock<std::__1::shared_mutex>::shared_lock[abi:de190102] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/shared_mutex:322
#6	0x000000010d41f77d in std::__1::shared_lock<std::__1::shared_mutex>::shared_lock[abi:de190102] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/shared_mutex:321
#7	0x000000010d71e941 in facebook::react::ComponentDescriptorRegistry::findComponentDescriptorByHandle_DO_NOT_USE_THIS_IS_BROKEN at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp:119
#8	0x000000010d7d2c79 in facebook::react::Scheduler::findComponentDescriptorByHandle_DO_NOT_USE_THIS_IS_BROKEN at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp:220
#9	0x000000010dadc8bd in -[RCTScheduler findComponentDescriptorByHandle_DO_NOT_USE_THIS_IS_BROKEN:] at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/React/Fabric/RCTScheduler.mm:174
#10	0x000000010dafd81b in -[RCTSurfacePresenter synchronouslyUpdateViewOnUIThread:props:] at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/React/Fabric/RCTSurfacePresenter.mm:165
#11	0x000000010d9d2166 in -[RCTPropsAnimatedNode updateView] at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/Libraries/NativeAnimation/Nodes/RCTPropsAnimatedNode.mm:66
#12	0x000000010d9d35ca in -[RCTPropsAnimatedNode performUpdate] at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/Libraries/NativeAnimation/Nodes/RCTPropsAnimatedNode.mm:142
#13	0x000000010d9b893e in -[RCTAnimatedNode updateNodeIfNecessary] at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/Libraries/NativeAnimation/Nodes/RCTAnimatedNode.mm:104
#14	0x000000010d9cb3d4 in __49-[RCTNativeAnimatedNodesManager updateAnimations]_block_invoke at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.mm:506
#15	0x000000010caf4442 in __NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__ ()
#16	0x000000010cc1e7fd in -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] ()
#17	0x000000010d9cb33c in -[RCTNativeAnimatedNodesManager updateAnimations] at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.mm:504
#18	0x000000010d9ca721 in -[RCTNativeAnimatedNodesManager stepAnimations:] at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.mm:470
#19	0x000000010b678e6b in CA::Display::DisplayLinkItem::dispatch_ ()
#20	0x000000010b6749d5 in CA::Display::DisplayLink::dispatch_items ()
#21	0x000000010b67bb7e in CA::Display::DisplayLink::dispatch_deferred_display_links ()
#22	0x000000013fb6746c in _UIUpdateSequenceRun ()
#23	0x000000014087a6a4 in schedulerStepScheduledMainSection ()
#24	0x00000001408798dd in runloopSourceCallback ()
#25	0x000000010cb0bcd8 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#26	0x000000010cb0bc1a in __CFRunLoopDoSource0 ()
#27	0x000000010cb0b424 in __CFRunLoopDoSources0 ()
#28	0x000000010cb05b7a in __CFRunLoopRun ()
#29	0x000000010cb053e3 in CFRunLoopRunSpecific ()
#30	0x000000012030e0cb in GSEventRunModal ()
#31	0x000000014098c043 in -[UIApplication _run] ()
#32	0x00000001409909f6 in UIApplicationMain ()
#33	0x000000010d394678 in main at /Users/boga/Work/OSS/RNMBGL/maps/example/ios/RNMapboxGLExample/main.m:15
#34	0x0000000108d9d45a in start_sim ()
#35	0x00000002008b2530 in start ()
com.facebook.react.runtime.JavaScript (10)#0	0x0000000111c00316 in __ulock_wait ()
#1	0x000000010af11854 in _dlock_wait ()
#2	0x000000010af116ab in _dispatch_thread_event_wait_slow ()
#3	0x000000010af22100 in __DISPATCH_WAIT_FOR_QUEUE__ ()
#4	0x000000010af21b1e in _dispatch_sync_f_slow ()
#5	0x000000010d5f1f87 in RCTUnsafeExecuteOnMainQueueSyncWithError at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/React/Base/RCTUtils.mm:324
#6	0x000000010d9a6d59 in -[RCTTurboModuleManager _provideObjCModule:moduleHolder:shouldPerfLog:moduleProvider:] at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm:608
#7	0x000000010d9a68b0 in -[RCTTurboModuleManager _provideObjCModule:moduleProvider:] at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm:547
#8	0x000000010d9a9347 in -[RCTTurboModuleManager moduleForName:warnOnLookupFailure:] at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm:994
#9	0x000000010d9a92de in -[RCTTurboModuleManager moduleForName:] at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm:983
#10	0x000000010d58af68 in -[RCTModuleRegistry moduleForName:lazilyLoadIfNecessary:] at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/React/Base/RCTModuleRegistry.m:44
#11	0x000000010d4f400c in -[RCTBridgeProxy moduleForName:lazilyLoadIfNecessary:] at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/React/Base/RCTBridgeProxy.mm:121
#12	0x000000010d79a506 in facebook::react::getViewManagerClass at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropComponentDescriptor.mm:90
#13	0x000000010d798f33 in facebook::react::constructCoordinator at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropComponentDescriptor.mm:113
#14	0x000000010d798c8b in facebook::react::LegacyViewManagerInteropComponentDescriptor::LegacyViewManagerInteropComponentDescriptor at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropComponentDescriptor.mm:141
#15	0x000000010d7993bd in facebook::react::LegacyViewManagerInteropComponentDescriptor::LegacyViewManagerInteropComponentDescriptor at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropComponentDescriptor.mm:142
#16	0x000000010da92168 in std::__1::make_unique[abi:de190102]<facebook::react::LegacyViewManagerInteropComponentDescriptor const, facebook::react::ComponentDescriptorParameters const&> at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__memory/unique_ptr.h:635
#17	0x000000010da92108 in facebook::react::concreteComponentDescriptorConstructor<facebook::react::LegacyViewManagerInteropComponentDescriptor> at /Users/boga/Work/OSS/RNMBGL/maps/example/ios/Pods/Headers/Public/React-Fabric/react/renderer/componentregistry/ComponentDescriptorProvider.h:52
#18	0x000000010d71dbdd in facebook::react::ComponentDescriptorRegistry::add at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp:35
#19	0x000000010d718164 in facebook::react::ComponentDescriptorProviderRegistry::add at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorProviderRegistry.cpp:40
#20	0x000000010da54076 in -[RCTComponentViewFactory _registerComponentIfPossible:] at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/React/Fabric/Mounting/RCTComponentViewFactory.mm:170
#21	0x000000010da5dd14 in +[RCTComponentViewFactory currentComponentViewFactory]::'block-literal'::$_1::operator()(char const*) const at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/React/Fabric/Mounting/RCTComponentViewFactory.mm:91
#22	0x000000010da5dcc0 in std::__1::__invoke[abi:de190102]<+[RCTComponentViewFactory currentComponentViewFactory]::'block-literal'::$_1&, char const*> at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__type_traits/invoke.h:149
#23	0x000000010da5dc6d in std::__1::__invoke_void_return_wrapper<void, true>::__call[abi:de190102]<+[RCTComponentViewFactory currentComponentViewFactory]::'block-literal'::$_1&, char const*> at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__type_traits/invoke.h:224
#24	0x000000010da5dc45 in std::__1::__function::__alloc_func<+[RCTComponentViewFactory currentComponentViewFactory]::'block-literal'::$_1, std::__1::allocator<+[RCTComponentViewFactory currentComponentViewFactory]::'block-literal'::$_1>, void (char const*)>::operator()[abi:de190102] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:171
#25	0x000000010da5cca1 in std::__1::__function::__func<+[RCTComponentViewFactory currentComponentViewFactory]::'block-literal'::$_1, std::__1::allocator<+[RCTComponentViewFactory currentComponentViewFactory]::'block-literal'::$_1>, void (char const*)>::operator() at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:313
#26	0x000000010d71bfd6 in std::__1::__function::__value_func<void (char const*)>::operator()[abi:de190102] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:430
#27	0x000000010d7187dd in std::__1::function<void (char const*)>::operator() at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:989
#28	0x000000010d71868c in facebook::react::ComponentDescriptorProviderRegistry::request at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorProviderRegistry.cpp:62
#29	0x000000010d71e34c in facebook::react::ComponentDescriptorRegistry::at at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp:71
#30	0x000000010d845672 in facebook::react::UIManager::createNode at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp:69
#31	0x000000010d8753dd in facebook::react::UIManagerBinding::get(facebook::jsi::Runtime&, facebook::jsi::PropNameID const&)::$_0::operator()(facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long) const at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp:225
#32	0x000000010d875106 in std::__1::__invoke[abi:de190102]<facebook::react::UIManagerBinding::get(facebook::jsi::Runtime&, facebook::jsi::PropNameID const&)::$_0&, facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long> at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__type_traits/invoke.h:149
#33	0x000000010d875090 in std::__1::__invoke_void_return_wrapper<facebook::jsi::Value, false>::__call[abi:de190102]<facebook::react::UIManagerBinding::get(facebook::jsi::Runtime&, facebook::jsi::PropNameID const&)::$_0&, facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long> at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__type_traits/invoke.h:216
#34	0x000000010d875040 in std::__1::__function::__alloc_func<facebook::react::UIManagerBinding::get(facebook::jsi::Runtime&, facebook::jsi::PropNameID const&)::$_0, std::__1::allocator<facebook::react::UIManagerBinding::get(facebook::jsi::Runtime&, facebook::jsi::PropNameID const&)::$_0>, facebook::jsi::Value (facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long)>::operator()[abi:de190102] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:171
#35	0x000000010d873fb4 in std::__1::__function::__func<facebook::react::UIManagerBinding::get(facebook::jsi::Runtime&, facebook::jsi::PropNameID const&)::$_0, std::__1::allocator<facebook::react::UIManagerBinding::get(facebook::jsi::Runtime&, facebook::jsi::PropNameID const&)::$_0>, facebook::jsi::Value (facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long)>::operator() at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:313
#36	0x000000011143d1c1 in facebook::hermes::HermesRuntimeImpl::HFContext::func ()
#37	0x00000001114fa6ec in hermes::vm::NativeFunction::_nativeCall ()
#38	0x00000001115157ac in hermes::vm::Interpreter::interpretFunction<false, false> ()
#39	0x0000000111514e6c in hermes::vm::Runtime::interpretFunctionImpl ()
#40	0x00000001114fa984 in hermes::vm::JSFunction::_callImpl ()
#41	0x00000001114f7e13 in hermes::vm::Callable::executeCall0 ()
#42	0x000000011155cc74 in hermes::vm::Runtime::drainJobs ()
#43	0x000000011142e49e in facebook::hermes::HermesRuntimeImpl::drainMicrotasks ()
#44	0x000000010de01c00 in facebook::react::RuntimeScheduler_Modern::performMicrotaskCheckpoint at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Modern.cpp:417
#45	0x000000010de019a0 in facebook::react::RuntimeScheduler_Modern::runEventLoopTick at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Modern.cpp:326
#46	0x000000010de0156a in facebook::react::RuntimeScheduler_Modern::runEventLoop at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Modern.cpp:269
#47	0x000000010de0aba2 in facebook::react::RuntimeScheduler_Modern::scheduleEventLoop()::$_0::operator()(facebook::jsi::Runtime&) const at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Modern.cpp:251
#48	0x000000010de0ab6d in std::__1::__invoke[abi:de190102]<facebook::react::RuntimeScheduler_Modern::scheduleEventLoop()::$_0&, facebook::jsi::Runtime&> at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__type_traits/invoke.h:149
#49	0x000000010de0ab1d in std::__1::__invoke_void_return_wrapper<void, true>::__call[abi:de190102]<facebook::react::RuntimeScheduler_Modern::scheduleEventLoop()::$_0&, facebook::jsi::Runtime&> at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__type_traits/invoke.h:224
#50	0x000000010de0aaf5 in std::__1::__function::__alloc_func<facebook::react::RuntimeScheduler_Modern::scheduleEventLoop()::$_0, std::__1::allocator<facebook::react::RuntimeScheduler_Modern::scheduleEventLoop()::$_0>, void (facebook::jsi::Runtime&)>::operator()[abi:de190102] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:171
#51	0x000000010de09b31 in std::__1::__function::__func<facebook::react::RuntimeScheduler_Modern::scheduleEventLoop()::$_0, std::__1::allocator<facebook::react::RuntimeScheduler_Modern::scheduleEventLoop()::$_0>, void (facebook::jsi::Runtime&)>::operator() at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:313
#52	0x000000010d5698c6 in std::__1::__function::__value_func<void (facebook::jsi::Runtime&)>::operator()[abi:de190102] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:430
#53	0x000000010d56807d in std::__1::function<void (facebook::jsi::Runtime&)>::operator() at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:989
#54	0x000000010dc0aff8 in _ZZZN8facebook5react13ReactInstanceC1ENSt3__110unique_ptrINS0_9JSRuntimeENS2_14default_deleteIS4_EEEENS2_10shared_ptrINS0_18MessageQueueThreadEEENS8_INS0_12TimerManagerEEENS2_8functionIFvRNS_3jsi7RuntimeERKNS0_14JsErrorHandler14ProcessedErrorEEEEPNS0_18jsinspector_modern10HostTargetEENK3$_0clINSD_IFvSG_EEEEEDaT_ENKUlvE_clEv at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/runtime/ReactInstance.cpp:83
#55	0x000000010dc0af55 in _ZNSt3__18__invokeB8de190102IRZZN8facebook5react13ReactInstanceC1ENS_10unique_ptrINS2_9JSRuntimeENS_14default_deleteIS5_EEEENS_10shared_ptrINS2_18MessageQueueThreadEEENS9_INS2_12TimerManagerEEENS_8functionIFvRNS1_3jsi7RuntimeERKNS2_14JsErrorHandler14ProcessedErrorEEEEPNS2_18jsinspector_modern10HostTargetEENK3$_0clINSE_IFvSH_EEEEEDaT_EUlvE_JEEEDTclclsr3stdE7declvalISW_EEspclsr3stdE7declvalIT0_EEEEOSW_DpOSZ_ at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__type_traits/invoke.h:149
#56	0x000000010dc0af15 in _ZNSt3__128__invoke_void_return_wrapperIvLb1EE6__callB8de190102IJRZZN8facebook5react13ReactInstanceC1ENS_10unique_ptrINS4_9JSRuntimeENS_14default_deleteIS7_EEEENS_10shared_ptrINS4_18MessageQueueThreadEEENSB_INS4_12TimerManagerEEENS_8functionIFvRNS3_3jsi7RuntimeERKNS4_14JsErrorHandler14ProcessedErrorEEEEPNS4_18jsinspector_modern10HostTargetEENK3$_0clINSG_IFvSJ_EEEEEDaT_EUlvE_EEEvDpOT_ at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__type_traits/invoke.h:224
#57	0x000000010dc0aeed in _ZNSt3__110__function12__alloc_funcIZZN8facebook5react13ReactInstanceC1ENS_10unique_ptrINS3_9JSRuntimeENS_14default_deleteIS6_EEEENS_10shared_ptrINS3_18MessageQueueThreadEEENSA_INS3_12TimerManagerEEENS_8functionIFvRNS2_3jsi7RuntimeERKNS3_14JsErrorHandler14ProcessedErrorEEEEPNS3_18jsinspector_modern10HostTargetEENK3$_0clINSF_IFvSI_EEEEEDaT_EUlvE_NS_9allocatorISY_EEFvvEEclB8de190102Ev at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:171
#58	0x000000010dc09e29 in _ZNSt3__110__function6__funcIZZN8facebook5react13ReactInstanceC1ENS_10unique_ptrINS3_9JSRuntimeENS_14default_deleteIS6_EEEENS_10shared_ptrINS3_18MessageQueueThreadEEENSA_INS3_12TimerManagerEEENS_8functionIFvRNS2_3jsi7RuntimeERKNS3_14JsErrorHandler14ProcessedErrorEEEEPNS3_18jsinspector_modern10HostTargetEENK3$_0clINSF_IFvSI_EEEEEDaT_EUlvE_NS_9allocatorISY_EEFvvEEclEv at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:313
#59	0x000000010d4f14de in std::__1::__function::__value_func<void ()>::operator()[abi:de190102] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:430
#60	0x000000010d4f1425 in std::__1::function<void ()>::operator() at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:989
#61	0x000000010d544e25 in facebook::react::tryAndReturnError at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/React/CxxModule/RCTCxxUtils.mm:73
#62	0x000000010d573201 in facebook::react::RCTMessageThread::tryFunc at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/React/CxxBridge/RCTMessageThread.mm:68
#63	0x000000010d5775af in facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_0::operator()() const at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/React/CxxBridge/RCTMessageThread.mm:81
#64	0x000000010d577555 in std::__1::__invoke[abi:de190102]<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_0&> at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__type_traits/invoke.h:149
#65	0x000000010d577515 in std::__1::__invoke_void_return_wrapper<void, true>::__call[abi:de190102]<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_0&> at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__type_traits/invoke.h:224
#66	0x000000010d5774ed in std::__1::__function::__alloc_func<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_0, std::__1::allocator<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_0>, void ()>::operator()[abi:de190102] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:171
#67	0x000000010d576439 in std::__1::__function::__func<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_0, std::__1::allocator<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_0>, void ()>::operator() at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:313
#68	0x000000010d4f14de in std::__1::__function::__value_func<void ()>::operator()[abi:de190102] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:430
#69	0x000000010d4f1425 in std::__1::function<void ()>::operator() at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.5.sdk/usr/include/c++/v1/__functional/function.h:989
#70	0x000000010d572faa in invocation function for block in facebook::react::RCTMessageThread::runAsync(std::__1::function<void ()>) at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/React/CxxBridge/RCTMessageThread.mm:44
#71	0x000000010cb0bacf in __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ ()
#72	0x000000010cb0b29b in __CFRunLoopDoBlocks ()
#73	0x000000010cb0605a in __CFRunLoopRun ()
#74	0x000000010cb053e3 in CFRunLoopRunSpecific ()
#75	0x000000010dbf71b3 in +[RCTJSThreadManager runRunLoop] at /Users/boga/Work/OSS/RNMBGL/maps/example/node_modules/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTJSThreadManager.mm:102
#76	0x0000000114e483f0 in __NSThread__start__ ()
#77	0x0000000111d6ce59 in _pthread_start ()
#78	0x0000000111d68857 in thread_start ()

@whiteHatCip

whiteHatCip commented Aug 29, 2025 •

Copy link
Copy Markdown
Contributor Author

Also this is somewhat documented in react-native source:

https://github.com/facebook/react-native/blob/7404fb620bb609dddd788bef16fdb9390ef2478b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm#L603-L611

com.facebook.react.runtime.JavaScript (10)

Well I didn't know that it was - like you said - somewhat documented, and it's an absolute coincidence that I found the solution to our deadlock issue. anyway, I am glad that this issue is no more 😃

Gotta say, tho, if the one I proposed is to be considered a workaround, do you think that there would be a "more recommended" way to do the same things? what do you think?

@whiteHatCip
whiteHatCip marked this pull request as ready for review August 29, 2025 13:58
@mfazekas

Copy link
Copy Markdown
Contributor

@whiteHatCip one thing I'm wandering is why is new arch using RNMBXCircleLayerViewManager, it should be using RNMBXCircleLayerComponentView

@mfazekas
mfazekas merged commit d7ef2fe into rnmapbox:main Aug 29, 2025
@whiteHatCip

Copy link
Copy Markdown
Contributor Author

@whiteHatCip one thing I'm wandering is why is new arch using RNMBXCircleLayerViewManager, it should be using RNMBXCircleLayerComponentView

Is new arch using it? why do you ask?

@whiteHatCip
whiteHatCip deleted the defects/app-freezes-randomly branch August 29, 2025 14:19
@mfazekas

Copy link
Copy Markdown
Contributor

@whiteHatCip one thing I'm wandering is why is new arch using RNMBXCircleLayerViewManager, it should be using RNMBXCircleLayerComponentView

Is new arch using it? why do you ask?

The deadlock happened in new architecture.

The files you changed was in old architecture RNMBXCircleLayerViewManager -> requiresMainQueueSetup
But we have fabric component for RNMBXCircrleLayer, RNMBXCircleLayerComponentView so I don't see why it's using the legacy RNMBXCircleLayerViewManager.

@whiteHatCip

whiteHatCip commented Aug 29, 2025 •

Copy link
Copy Markdown
Contributor Author

@whiteHatCip one thing I'm wandering is why is new arch using RNMBXCircleLayerViewManager, it should be using RNMBXCircleLayerComponentView

Is new arch using it? why do you ask?

The deadlock happened in new architecture.

The files you changed was in old architecture RNMBXCircleLayerViewManager -> requiresMainQueueSetup But we have fabric component for RNMBXCircrleLayer, RNMBXCircleLayerComponentView so I don't see why it's using the legacy RNMBXCircleLayerViewManager.

To be honest I am not sure that RNMBXCircleLayer was involved in the deadlock issue that this PR was addressing. I changed return true -> return false in all those components that represented views and that apparently were not doing anything with UIKit (hence they didn't need to return true).

Circle layer was just an example. Yes it could be any component. And yes the deadlock is by changing the requiresMainQueueSetup to false. I agree that this change will not cause any issue, I also agree that this change fixes the deadlock.

If RNMBXCircleLayer is never invoked when the app is running with new arch enabled, and you think that returning false could be an issue for old architecture users, we could revert just that file.

I kept the PR in draft mode because I was waiting for your opinion on my proposal, and since you approved it, I thought that it was good the way it was.

Again this is good change, and fixes the deadlock.

BUT in new architecture react-native should be using our Fabric components RNMBXCircleLayerComponentView andRNMBX*ComponentView in general. And it should not be calling RNMBX*ViewManager as that's our legacy old-arch component manager. So there is something wrong with our new arch setup, and react-native is using our old arch code for some reason. RN has a compatibility layer to support legacy libs, but in our case we have fabric code, so RN should use that.

This branch was previously deployed

1 inactive deployment
CI with Mapbox Tokens — 82e0e2fa Deployed Aug 29, 2025 by whiteHatCip
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.

[Bug]: App freeze on iOS with @rnmapbox/maps + react-native@0.80.0 when adding elements to MapView

2 participants