Crash on iOS: UIKitCore -[UIApplication _run] with CFRunLoopRun

Hello everyone,

I’m experiencing a crash in my iOS application that’s occurring predominantly on devices running iOS 16.6.0. The crash seems to happen on the main thread during a UI operation, specifically within the UIKitCore framework.

Crash Log Summary

Thread 0 Crashed: 0 libsystem_kernel.dylib 0xca4 mach_msg2_trap + 8 1 libsystem_kernel.dylib 0x13b74 mach_msg2_internal + 80 2 libsystem_kernel.dylib 0x13e4c mach_msg_overwrite + 540 3 libsystem_kernel.dylib 0x11e8 mach_msg + 24 4 CoreFoundation 0x79024 __CFRunLoopServiceMachPort + 160 5 CoreFoundation 0x7a250 __CFRunLoopRun + 1208 6 CoreFoundation 0x7f3ec CFRunLoopRunSpecific + 612 7 GraphicsServices 0x135c GSEventRunModal + 164 8 UIKitCore 0x39cf58 -[UIApplication _run] + 888 9 UIKitCore 0x39cbbc UIApplicationMain + 340 10 MyApp 0x24050 main + 51 (AppDelegate.swift:51) 11 ??? 0x1d3594dec (Missing)

I’ve attached the full crash

and would appreciate any insights or recommendations on how to resolve this issue.

I recommend that you remove your third-party crash reporter and see if you can get an Apple crash report for this. If so, please post it here. See Posting a Crash Report for advice on how to do that.

Third-party crash reporters are always problematic, as I explain in detail in Implementing Your Own Crash Reporter. However, in this specific case the crash report is most definitely bogus. Consider this:

Crashed: com.apple.main-thread
0  libsystem_kernel.dylib 0x1728 mach_msg2_trap + 8
1  libsystem_kernel.dylib 0x4e38 mach_msg2_internal + 80
2  libsystem_kernel.dylib 0x4d50 mach_msg_overwrite + 424
3  libsystem_kernel.dylib 0x4b9c mach_msg + 24
4  CoreFoundation         0x547cc __CFRunLoopServiceMachPort + 160
5  CoreFoundation         0x53e78 __CFRunLoopRun + 1212
6  CoreFoundation         0x535b8 CFRunLoopRunSpecific + 572
7  GraphicsServices       0x11c4 GSEventRunModal + 164
8  UIKitCore              0x3dfb6c -[UIApplication _run] + 816
9  UIKitCore              0x48dfdc UIApplicationMain + 340
10 App                    0xe6b61c main + 23 (AppDelegate.swift:23)

Your main thread is blocked in mach_msg2_trap waiting for an event to come in. It can’t possibly ‘crash’ while it’s in that state.

Now consider this:

BSXPCCnx:com.apple.backboard.hid-services.xpc (BSCnx:client:BKHIDEventDeliveryManager)
0  App                     0x1653638 GMSx_absl::Mutex::~Mutex() + 766
1  libsystem_c.dylib         0x23b64 exit + 32
2  BackBoardServices         0x57bf0 -[BKSHIDEventDeliveryManager _initForTestingWithService:] + 98
3  BoardServices              0xbae8 __31-[BSServiceConnection activate]_block_invoke.182 + 128
4  BoardServices             0x17620 __61-[BSXPCServiceConnectionEventHandler _connectionInvalidated:]_block_invoke + 196
5  BoardServices              0x8f64 BSXPCServiceConnectionExecuteCallOut + 240
6  BoardServices             0x18e5c -[BSXPCServiceConnectionEventHandler _connectionInvalidated:] + 180
7  libdispatch.dylib          0x2370 _dispatch_call_block_and_release + 32
8  libdispatch.dylib          0x40d0 _dispatch_client_callout + 20
9  libdispatch.dylib          0xb6d8 _dispatch_lane_serial_drain + 744
10 libdispatch.dylib          0xc214 _dispatch_lane_invoke + 432
11 libdispatch.dylib         0x17258 _dispatch_root_queue_drain_deferred_wlh + 288
12 libdispatch.dylib         0x16aa4 _dispatch_workloop_worker_thread + 540
13 libsystem_pthread.dylib    0x4c7c _pthread_wqthread + 288
14 libsystem_pthread.dylib    0x1488 start_wqthread + 8

It suggest that your app is in the middle of terminating and somehow got stuck in a mutex destructor, probably due to an atexit handler.

Trying to untangle this without a trustworthy crash report is a challenge. However, even without that there’s still something you can do: Get rid of that atexit handler. This looks like it’s coming from a C++ static destructor. Running a static destructor at exit like this is almost always a mistake, because once the exit completes the entire process will go away.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Crash on iOS: UIKitCore -[UIApplication _run] with CFRunLoopRun
 
 
Q