CLMonitor related crash - EXC_BAD_ACCESS (SIGSEGV)

Hello

I started using CLMonitor on my App, and I am noticing the following crash on Xcode Organizer for dozens of my app users:

Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000001
Exception Codes: 0x0000000000000001, 0x0000000000000001
VM Region Info: 0x1 is not in any region.  Bytes before following region: ………….
      REGION TYPE                 START - END      [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                   ………-…….. [  176K] r-x/r-x SM=COW  /var/containers/Bundle/Application/.........../MyApp
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler […..]

Thread 4 name:
Thread 4 Crashed:
0   libswiftCoreLocation.dylib    	0x000000021680b4c8 @objc completion handler block implementation for @escaping @callee_unowned @convention(block) (@unowned CLMonitor) -> () with result type CLMonitor + 44 (<compiler-generated>:0)
1   CoreLocation                  	0x0000000196cdddd4 __76-[CLMonitorConfiguration vendMonitorWithIdentityAndAuthorizationAttributes:]_block_invoke + 216 (CLMonitorConfiguration.m:195)
2   libdispatch.dylib             	0x0000000191138370 _dispatch_call_block_and_release + 32 (init.c:1549)
3   libdispatch.dylib             	0x000000019113a0d0 _dispatch_client_callout + 20 (object.m:576)
4   libdispatch.dylib             	0x00000001911416d8 _dispatch_lane_serial_drain + 744 (queue.c:3934)
5   libdispatch.dylib             	0x00000001911421e0 _dispatch_lane_invoke + 380 (queue.c:4025)
6   libdispatch.dylib             	0x000000019114d258 _dispatch_root_queue_drain_deferred_wlh + 288 (queue.c:7193)
7   libdispatch.dylib             	0x000000019114caa4 _dispatch_workloop_worker_thread + 540 (queue.c:6787)
8   libsystem_pthread.dylib       	0x0000000211933c7c _pthread_wqthread + 288 (pthread.c:2696)
9   libsystem_pthread.dylib       	0x0000000211930488 start_wqthread + 8

Does anyone have similar issue when using CLMonitor?

How can I debug / fix this issue?

Is it an CLMonitor API bug? Should I file a bug report?

Answered by DTS Engineer in 818774022

I attached a crash log with the details I can share for the moment

So, this crash log is a great example of why I always try to get a full log before trying to diagnose anything. It's very easy to focus on the threads that seem to be the source of the problem without realizing there are other concerns in play.

In this case, my biggest concern is the combination 6 threads and your main thread state:

32  MyMainModule    	0x00000001038d4064 +[MyMainModuleInitClass load] + 100 (MyMainModuleInitClass.m:32)
33  libobjc.A.dylib               	0x0000000186724714 load_images + 736 (objc-runtime-new.mm:3740)
34  dyld                          	0x00000001aedfad10 dyld4::RuntimeState::notifyObjCInit(dyld4::Loader const*) + 576 (DyldRuntimeState.cpp:2139)
35  dyld                          	0x00000001aee33908 dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array&, dyld3::Array&) const + 300 (Loader.cpp:2316)
36  dyld                          	0x00000001aee338b4 dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array&, dyld3::Array&) const + 216 (Loader.cpp:2309)
37  dyld                          	0x00000001aee352c8 dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const::$_0::operator()() const + 180 (Loader.cpp:2330)
38  dyld                          	0x00000001aee00c00 dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const + 412 (Loader.cpp:2326)
39  dyld                          	0x00000001aedf0280 dyld4::APIs::runAllInitializersForMain() + 296 (DyldAPIs.cpp:4150)
40  dyld                          	0x00000001aee04d10 dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 3404 (dyldMain.cpp:902)
41  dyld                          	0x00000001aee299f8 dyld4::start(dyld4::KernelArgs*, void*, void*)::$_0::operator()() const + 544 (dyldMain.cpp:1322)
42  dyld                          	0x00000001aee22cb0 start + 2188 (dyldMain.cpp:1299)

Your app is currently in library load time and has not yet called main. In other words, you've kicked off most of your apps functionality, including initializing system framework like CoreLocation, BEFORE your app has initialized UIKit and started it's event loop.

The systems behavior in this state is basically... undefined. Most of our framework implicitly assume that they're running "in an app" and rely on a variety of implicit configuration/state that comes from that configuration. Lots of things do "work" (which is why your app works at all), but that's basically "accidental", NOT because of any special effort on the frameworks part.

Related to that point, I also noticed that your app crashing very early in a background launch:

Role:                Non UI
...
Date/Time:           2024-11-21 14:51:03.5555 +0100
Launch Time:         2024-11-21 14:51:03.1668 +0100

A few questions about this:

  • Is that consistent across all the crash logs you've gotten do some of the logs list a different role? Particularly foreground crashes?

  • Do you what might be triggering that launch (besides CoreLocation)?

The issue here is that the process a daemon uses to launch an app into the background is intended to work something like this:

  1. The daemon asks the system to launch the app.
  2. The app is launched.
  3. The app registers itself with the system early in UIApplicationMain().
  4. The app connects "back" to the daemon as part of it's normal start up process.

Focusing on point 4, most of our background APIs have some part of the documentation that includes a statement/verbiage similar to this:

"If your app actively receives and processes location updates and terminates, it should restart those APIs upon launch in order to continue receiving updates."

The issue here is that while CoreLocation initiates your app launch, it needs your app to connect BACK to it before it can actually "do" anything with your app. It needs that connection "back" from your app both to deliver events and, more importantly, to keep your app awake to have events delivered to it.

The problem with initializing at library load time (which is what your app is doing) is that you can "flip" the order of 3 & 4. What happens after that point depends entirely on the internal details of locationd and the daemon's that manage app lifetime. In the worst case, locationd is unable to properly "manage" your app because doing so relies on internal "infrastructure" that does actually exist yet (because that infrastructure is initialized in #3).

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

I started using CLMonitor on my App, and I am noticing the following crash on Xcode Organizer for dozens of my app users:

My guess is that there's something happening on your other threads that's disrupting CoreLocation. Please post the full crash log (or more than one) and I'll see what I can determine.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Thanks for your answer

Here are more details about the issue:

I have another thread having CLMonitor in its stacktrace:

Thread 3:
0   libsystem_kernel.dylib        	0x00000001d97f63e4 kevent_id + 8
1   libdispatch.dylib             	0x000000019115cb00 _dispatch_kq_poll + 228 (event_kevent.c:760)
2   libdispatch.dylib             	0x000000019115d50c _dispatch_event_loop_wait_for_ownership + 436 (event_kevent.c:2236)
3   libdispatch.dylib             	0x0000000191149a20 __DISPATCH_WAIT_FOR_QUEUE__ + 340 (queue.c:1704)
4   libdispatch.dylib             	0x00000001911495e8 _dispatch_sync_f_slow + 148 (queue.c:1799)
5   CoreLocation                  	0x0000000196df4a2c -[CLMonitor _getMonitoringRecords] + 188 (CLMonitor.mm:179)
6   libswiftCoreLocation.dylib    	0x000000021680ae54 CLMonitor.init(_:) + 84 (CLMonitor.swift:281)
7   libswiftCoreLocation.dylib    	0x000000021680a991 CLMonitor.__allocating_init(_:) + 1 (CLMonitor.swift:0)
8   MyModule    	0x0000000103918f55 closure #1 in MyService.setupTask() + 1 (MyService.swift:33)
9   MyModule    	0x00000001039145c1 $sxIeAgHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRyt_Tg5TATQ0_ + 1 (/<compiler-generated>:0)
10  libswift_Concurrency.dylib    	0x0000000194b47e39 completeTaskWithClosure(swift::AsyncContext*, swift::SwiftError*) + 1 (Task.cpp:497)

no other thread mention CoreLocation or CLMonitor except these 2 threads.

and here is what my setupTask function look like

 func setupTask() {
        self.myTask = Task(priority: .high) {
            if #available(iOS 18.0, *) {
				// create my session
            }

            let monitor = await CLMonitor(myIdentifier)
            self.myMonitor = monitor
            for try await event in await monitor.events {
                if event.state == .unsatisfied {
                    let record = await monitor.record(for: event.identifier)
					// use record condition and lastEvent

                } else if event.state == .satisfied {
                    let record = await monitor.record(for: event.identifier)
					// use record condition and lastEvent
                }
            }
        }
    }

Here are more details about the issue: I have another thread having CLMonitor in its stacktrace:

I still need to see the full crash log to be able to offer the best guidance.

no other thread mention CoreLocation or CLMonitor except these 2 threads.

Having looked a very large number of random crash logs, it's almost impossible to predict what will or will not be interesting/useful in a crash log. This is why I've asked for the full log.

and here is what my setupTask function look like

I don't see any obvious issue in your code.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Thank you for your answer

I attached a crash log with the details I can share for the moment

Incident Identifier: 60D87321-6AB1-49C9-A565-8EEE865850CA
Distributor ID:      com.apple.AppStore
Hardware Model:      iPhone12,8
Process:             MyApp [8606]
Path:                /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/MyApp
Identifier:          com.my.app.bundle
Version:             5.9.1 (1121)
AppStoreTools:       16B39
AppVariant:          1:iPhone12,8:18
Code Type:           ARM-64 (Native)
Role:                Non UI
Parent Process:      launchd [1]
Coalition:           com.my.app.bundle [671]

Date/Time:           2024-11-21 14:51:03.5555 +0100
Launch Time:         2024-11-21 14:51:03.1668 +0100
OS Version:          iPhone OS 18.1 (22B83)
Release Type:        User
Baseband Version:    6.00.00
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000001
Exception Codes: 0x0000000000000001, 0x0000000000000001
VM Region Info: 0x1 is not in any region.  Bytes before following region: 4330733567
      REGION TYPE                 START - END      [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                   10221c000-102248000 [  176K] r-x/r-x SM=COW  /var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/MyApp
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [8606]

Triggered by Thread:  4


Thread 0 name:
Thread 0:
0   libsystem_kernel.dylib        	0x00000001d97f6b7c pread + 8
1   libsqlite3.dylib              	0x00000001b6a833fc seekAndRead + 96 (sqlite3.c:44032)
2   libsqlite3.dylib              	0x00000001b69f93c8 unixRead + 208 (sqlite3.c:44124)
3   libsqlite3.dylib              	0x00000001b69f6c14 sqlite3BtreeOpen + 3132 (sqlite3.c:79476)
4   libsqlite3.dylib              	0x00000001b69f40a4 openDatabase + 2424 (sqlite3.c:188918)
5   CoreData                      	0x0000000191418160 +[NSSQLiteConnection openAtPath:withKey:handle:flags:module:checkpointOnClose:] + 76 (NSSQLiteConnection.m:435)
6   CoreData                      	0x00000001913cd598 -[NSSQLiteConnection connect] + 1336 (NSSQLiteConnection.m:2239)
7   CoreData                      	0x000000019141f5f0 __32-[NSSQLCore _loadAndSetMetadata]_block_invoke + 96 (NSSQLCore.m:1954)
8   CoreData                      	0x00000001913cc8c0 __37-[NSSQLiteConnection performAndWait:]_block_invoke + 48 (NSSQLiteConnection.m:733)
9   libdispatch.dylib             	0x000000019113a0d0 _dispatch_client_callout + 20 (object.m:576)
10  libdispatch.dylib             	0x0000000191149750 _dispatch_lane_barrier_sync_invoke_and_complete + 56 (queue.c:1104)
11  CoreData                      	0x0000000191399c48 -[NSSQLiteConnection performAndWait:] + 176 (NSSQLiteConnection.m:730)
12  CoreData                      	0x000000019143cd34 -[NSSQLCore loadMetadata:] + 336 (NSSQLCore.m:2000)
13  CoreData                      	0x000000019143b3c8 __91-[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:]_block_invoke + 2332 (NSPersistentStoreCoordinator.m:1596)
14  CoreData                      	0x000000019139576c gutsOfBlockToNSPersistentStoreCoordinatorPerform + 204 (NSPersistentStoreCoordinator.m:407)
15  libdispatch.dylib             	0x000000019113a0d0 _dispatch_client_callout + 20 (object.m:576)
16  libdispatch.dylib             	0x0000000191149750 _dispatch_lane_barrier_sync_invoke_and_complete + 56 (queue.c:1104)
17  CoreData                      	0x0000000191388c00 _perform + 188 (NSPersistentStoreCoordinator.m:529)
18  CoreData                      	0x000000019143a718 -[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:] + 424 (NSPersistentStoreCoordinator.m:1483)
19  CoreData                      	0x0000000191451300 -[NSPersistentStoreCoordinator _doAddPersistentStoreWithDescription:privateCopy:completeOnMainThread:withHandler:] + 400 (NSPersistentStoreCoordinator.m:1379)
20  CoreData                      	0x00000001914510a4 -[NSPersistentStoreCoordinator addPersistentStoreWithDescription:completionHandler:] + 228 (NSPersistentStoreCoordinator.m:1457)
21  CoreData                      	0x00000001914518ec -[NSPersistentContainer _loadStoreDescriptions:withCompletionHandler:] + 184 (NSPersistentContainer.m:291)
22  CoreData                      	0x0000000191450b6c -[NSPersistentContainer loadPersistentStoresWithCompletionHandler:] + 248 (NSPersistentContainer.m:274)
23  MyDBModule
24  MyDBModule
25  MyDBModule
26  MyDBModule
27  MyMainModule
28  MyMainModule
29  MyMainModule
30  MyMainModule
31  MyMainModule
32  MyMainModule    	0x00000001038d4064 +[MyMainModuleInitClass load] + 100 (MyMainModuleInitClass.m:32)
33  libobjc.A.dylib               	0x0000000186724714 load_images + 736 (objc-runtime-new.mm:3740)
34  dyld                          	0x00000001aedfad10 dyld4::RuntimeState::notifyObjCInit(dyld4::Loader const*) + 576 (DyldRuntimeState.cpp:2139)
35  dyld                          	0x00000001aee33908 dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array&, dyld3::Array&) const + 300 (Loader.cpp:2316)
36  dyld                          	0x00000001aee338b4 dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array&, dyld3::Array&) const + 216 (Loader.cpp:2309)
37  dyld                          	0x00000001aee352c8 dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const::$_0::operator()() const + 180 (Loader.cpp:2330)
38  dyld                          	0x00000001aee00c00 dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const + 412 (Loader.cpp:2326)
39  dyld                          	0x00000001aedf0280 dyld4::APIs::runAllInitializersForMain() + 296 (DyldAPIs.cpp:4150)
40  dyld                          	0x00000001aee04d10 dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 3404 (dyldMain.cpp:902)
41  dyld                          	0x00000001aee299f8 dyld4::start(dyld4::KernelArgs*, void*, void*)::$_0::operator()() const + 544 (dyldMain.cpp:1322)
42  dyld                          	0x00000001aee22cb0 start + 2188 (dyldMain.cpp:1299)

Thread 1:
0   libsystem_pthread.dylib       	0x0000000211930480 start_wqthread + 0

Thread 2 name:
Thread 2:
0   libsystem_kernel.dylib        	0x00000001d97fcad0 __ulock_wait + 8
1   libdispatch.dylib             	0x000000019113aac0 _dlock_wait + 56 (lock.c:326)
2   libdispatch.dylib             	0x000000019113a7bc _dispatch_wait_on_address + 140 (lock.c:498)
3   libdispatch.dylib             	0x000000019113ae90 _dispatch_group_wait_slow + 56 (semaphore.c:214)
4   libswiftDispatch.dylib        	0x00000001927562a8 OS_dispatch_group.wait(wallTimeout:) + 24 (Dispatch.swift:165)
5   MyCoreModule
6   MyCoreModule
7   Foundation                    	0x0000000188041998 __NSOPERATION_IS_INVOKING_MAIN__ + 16 (NSOperation.m:2190)
8   Foundation                    	0x000000018803fbe8 -[NSOperation start] + 648 (NSOperation.m:1407)
9   Foundation                    	0x00000001880b7810 __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 16 (NSOperation.m:2221)
10  Foundation                    	0x00000001880b7440 __NSOQSchedule_f + 172 (NSOperation.m:2232)
11  libdispatch.dylib             	0x00000001911492e8 _dispatch_block_async_invoke2 + 148 (queue.c:574)
12  libdispatch.dylib             	0x000000019113a0d0 _dispatch_client_callout + 20 (object.m:576)
13  libdispatch.dylib             	0x000000019113d580 _dispatch_continuation_pop + 596 (queue.c:325)
14  libdispatch.dylib             	0x000000019113cbb0 _dispatch_async_redirect_invoke + 580 (queue.c:849)
15  libdispatch.dylib             	0x000000019114bd8c _dispatch_root_queue_drain + 392 (queue.c:7331)
16  libdispatch.dylib             	0x000000019114c590 _dispatch_worker_thread2 + 156 (queue.c:7399)
17  libsystem_pthread.dylib       	0x0000000211933c40 _pthread_wqthread + 228 (pthread.c:2709)
18  libsystem_pthread.dylib       	0x0000000211930488 start_wqthread + 8

Thread 3:
0   libsystem_kernel.dylib        	0x00000001d97f63e4 kevent_id + 8
1   libdispatch.dylib             	0x000000019115cb00 _dispatch_kq_poll + 228 (event_kevent.c:760)
2   libdispatch.dylib             	0x000000019115d50c _dispatch_event_loop_wait_for_ownership + 436 (event_kevent.c:2236)
3   libdispatch.dylib             	0x0000000191149a20 __DISPATCH_WAIT_FOR_QUEUE__ + 340 (queue.c:1704)
4   libdispatch.dylib             	0x00000001911495e8 _dispatch_sync_f_slow + 148 (queue.c:1799)
5   CoreLocation                  	0x0000000196df4a2c -[CLMonitor _getMonitoringRecords] + 188 (CLMonitor.mm:179)
6   libswiftCoreLocation.dylib    	0x000000021680ae54 CLMonitor.init(_:) + 84 (CLMonitor.swift:281)
7   libswiftCoreLocation.dylib    	0x000000021680a991 CLMonitor.__allocating_init(_:) + 1 (CLMonitor.swift:0)
8   MyMainModule    	0x0000000103918f55 closure #1 in MyService.setupTask() + 1 (MyService.swift:33)
9   MyMainModule    	0x00000001039145c1 $sxIeAgHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRyt_Tg5TATQ0_ + 1 (/:0)
10  libswift_Concurrency.dylib    	0x0000000194b47e39 completeTaskWithClosure(swift::AsyncContext*, swift::SwiftError*) + 1 (Task.cpp:497)

Thread 4 name:
Thread 4 Crashed:
0   libswiftCoreLocation.dylib    	0x000000021680b4c8 @objc completion handler block implementation for @escaping @callee_unowned @convention(block) (@unowned CLMonitor) -> () with result type CLMonitor + 44 (:0)
1   CoreLocation                  	0x0000000196cdddd4 __76-[CLMonitorConfiguration vendMonitorWithIdentityAndAuthorizationAttributes:]_block_invoke + 216 (CLMonitorConfiguration.m:195)
2   libdispatch.dylib             	0x0000000191138370 _dispatch_call_block_and_release + 32 (init.c:1549)
3   libdispatch.dylib             	0x000000019113a0d0 _dispatch_client_callout + 20 (object.m:576)
4   libdispatch.dylib             	0x00000001911416d8 _dispatch_lane_serial_drain + 744 (queue.c:3934)
5   libdispatch.dylib             	0x00000001911421e0 _dispatch_lane_invoke + 380 (queue.c:4025)
6   libdispatch.dylib             	0x000000019114d258 _dispatch_root_queue_drain_deferred_wlh + 288 (queue.c:7193)
7   libdispatch.dylib             	0x000000019114caa4 _dispatch_workloop_worker_thread + 540 (queue.c:6787)
8   libsystem_pthread.dylib       	0x0000000211933c7c _pthread_wqthread + 288 (pthread.c:2696)
9   libsystem_pthread.dylib       	0x0000000211930488 start_wqthread + 8

Thread 5 name:
Thread 5:
0   libsystem_kernel.dylib        	0x00000001d97fc12c __open + 8
1   libsystem_kernel.dylib        	0x00000001d97fc118 open + 40 (open-base.c:101)
2   Foundation                    	0x000000018812cf8c _NSOpenFileDescriptor + 44 (NSPlatform.m:460)
3   Foundation                    	0x000000018812ce74 -[NSConcreteFileHandle initWithURL:flags:createMode:error:] + 120 (NSFileHandle.m:689)
4   Foundation                    	0x000000018812cd04 +[NSFileHandle fileHandleForWritingToURL:error:] + 48 (NSFileHandle.m:341)
5   MyCoreModule            	0x000000010305c404 @nonobjc NSFileHandle.__allocating_init(forWritingTo:) + 92 (/:0)
6   MyCoreModule            	
7   MyCoreModule            	0x00000001030390b4 thunk for @escaping @callee_guaranteed () -> () + 28 (/:0)
8   libdispatch.dylib             	0x0000000191138370 _dispatch_call_block_and_release + 32 (init.c:1549)
9   libdispatch.dylib             	0x000000019113a0d0 _dispatch_client_callout + 20 (object.m:576)
10  libdispatch.dylib             	0x00000001911416d8 _dispatch_lane_serial_drain + 744 (queue.c:3934)
11  libdispatch.dylib             	0x00000001911421e0 _dispatch_lane_invoke + 380 (queue.c:4025)
12  libdispatch.dylib             	0x000000019114d258 _dispatch_root_queue_drain_deferred_wlh + 288 (queue.c:7193)
13  libdispatch.dylib             	0x000000019114caa4 _dispatch_workloop_worker_thread + 540 (queue.c:6787)
14  libsystem_pthread.dylib       	0x0000000211933c7c _pthread_wqthread + 288 (pthread.c:2696)
15  libsystem_pthread.dylib       	0x0000000211930488 start_wqthread + 8

Thread 6:
0   libsystem_pthread.dylib       	0x0000000211930480 start_wqthread + 0


Thread 4 crashed with ARM Thread State (64-bit):
    x0: 0x00000003014bc5a0   x1: 0x0000000303ea4480   x2: 0x0000000000003f07   x3: 0x0000000000003f07
    x4: 0x00000001ed207eb0   x5: 0x00000000c2c0b886   x6: 0x0000000303ea2700   x7: 0x0000000000000000
    x8: 0x0000000000000001   x9: 0x000000021680b49c  x10: 0x0000000000000001  x11: 0x001f000105086400
   x12: 0x000000000000000f  x13: 0x00000001050864b0  x14: 0x03000001ee163685  x15: 0x00000001ee163680
   x16: 0x0000000105189e40  x17: 0x753a000105184a40  x18: 0x0000000000000000  x19: 0x0000000105184a00
   x20: 0x00000003014bc9f0  x21: 0x0000000303ea4480  x22: 0x0000000300fa7f80  x23: 0x0000000000000000
   x24: 0x0000000300fb1540  x25: 0x0000000303ea42a0  x26: 0x00000003018ad270  x27: 0x0000000300fa72c0
   x28: 0x00000003028a0240   fp: 0x000000016de0e830   lr: 0x0000000196cdddd4
    sp: 0x000000016de0e820   pc: 0x000000021680b4c8 cpsr: 0x60000000
   esr: 0x92000046 (Data Abort) byte write Translation fault


Binary Images:
        0x10221c000 -         0x10248bfff MyApp arm64  <0eac0488f4a2396cadac928a0a403d3c> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/MyApp
        0x102614000 -         0x102627fff MyAModule arm64  <85bb61f8b2b73f2faa8c5173777924fa> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyAModule.framework/MyAModule
        0x102648000 -         0x102663fff MyBModule arm64  <6075f4151b6c3b50ab04194a7e402874> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyBModule.framework/MyBModule
        0x1026a0000 -         0x1026e3fff MyCModule arm64  <8648da3b7fca30b0a72895066ed4d904> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyCModule.framework/MyCModule
        0x10274c000 -         0x10275bfff MyDModule arm64   /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyDModule.framework/MyDModule
        0x10277c000 -         0x10278ffff MyEModule arm64   /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyEModule.framework/MyEModule
        0x1027c0000 -         0x1027d3fff MyFModule arm64   /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyFModule.framework/MyFModule
        0x102800000 -         0x10280ffff MyGModule arm64  <5827dceb777c3c8494ab4c2fc3bc285f> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyGModule.framework/MyGModule
        0x10282c000 -         0x10283ffff MyDBModule arm64  <87088dca04653d61b3371e952de75a4d> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyDBModule.framework/MyDBModule
        0x1028f4000 -         0x102a1bfff Alamofire arm64   /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/Alamofire.framework/Alamofire
        0x102bc0000 -         0x102ca7fff DGCharts arm64   /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/DGCharts.framework/DGCharts
        0x102eb0000 -         0x102f27fff MyHModule arm64   /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyHModule.framework/MyHModule
        0x10300c000 -         0x1030cbfff MyIModule arm64  <4fdd4206eb27376eb3840ef8066a209e> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyIModule.framework/MyIModule
        0x103210000 -         0x10325bfff MyJModule arm64  <7ab7c4fd385b36a5b89f554b8f2c178c> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyJModule.framework/MyJModule
        0x103338000 -         0x103353fff MyKModule arm64  <9b13907615fb3f069f403e170bb77770> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyKModule.framework/MyKModule
        0x103394000 -         0x1033bbfff MyLModule arm64  <9131921a454737ebb6280586cb444df7> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyLModule.framework/MyLModule
        0x103410000 -         0x103497fff MyMModule arm64  <98b6dc0dda5337cb900fd93ca92885aa> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyMModule.framework/MyMModule
        0x1035d8000 -         0x1035fbfff MyNModule arm64  <0aea8e6a075d3f1b8f46ef050e26b520> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyNModule.framework/MyNModule
        0x103648000 -         0x1036e3fff MyOModule arm64  <7514f1372907373593d73e36640ad338> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyOModule.framework/MyOModule
        0x103800000 -         0x103827fff MyPModule arm64   /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyPModule.framework/MyPModule
        0x103864000 -         0x103887fff MyQModule arm64  <442afc80b7e63f1789c796c6bbe747ae> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyQModule.framework/MyQModule
        0x1038d0000 -         0x10398bfff MyMainModule arm64   /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyMainModule.framework/MyMainModule
        0x103b10000 -         0x103b37fff MyRModule arm64   /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyRModule.framework/MyRModule
        0x103b88000 -         0x103bd7fff MySModule arm64  <141d2ebcb344305b82771adc0bf74db3> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MySModule.framework/MySModule
        0x103c98000 -         0x103d0bfff MyTModule arm64  <09b62ef051403d33b51f1e9eac91f58c> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/MyTModule.framework/MyTModule
        0x103de4000 -         0x103df3fff FBLPromises arm64  <18a42f8d80613f3d9dffdc9f64cd955d> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/FBLPromises.framework/FBLPromises
        0x103e10000 -         0x103e23fff FirebaseCore arm64  <87b23a32e53b3752b99a16eaf92cfbae> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/FirebaseCore.framework/FirebaseCore
        0x103e44000 -         0x103e4bfff FirebaseCoreExtension arm64  <44c624b741e93b26bb9b8a3d1c73d41d> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/FirebaseCoreExtension.framework/FirebaseCoreExtension
        0x103e58000 -         0x103e73fff FirebaseCoreInternal arm64  <7674a1cd7d9437329214f134155a02ec> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/FirebaseCoreInternal.framework/FirebaseCoreInternal
        0x103eb0000 -         0x103efffff FirebaseCrashlytics arm64  <49f359ab68b43b07894f1a8f61c569ff> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/FirebaseCrashlytics.framework/FirebaseCrashlytics
        0x103f84000 -         0x103f9bfff FirebaseDynamicLinks arm64  <5a1d59025ec73400b1a10f9f5fa3b03f> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/FirebaseDynamicLinks.framework/FirebaseDynamicLinks
        0x103fc4000 -         0x103fdbfff FirebaseInstallations arm64   /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/FirebaseInstallations.framework/FirebaseInstallations
        0x104004000 -         0x10403bfff FirebaseMessaging arm64   /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/FirebaseMessaging.framework/FirebaseMessaging
        0x104088000 -         0x104093fff FirebaseRemoteConfigInterop arm64  <9d5680ca20e43185aacd9dd45139498a> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/FirebaseRemoteConfigInterop.framework/FirebaseRemoteConfigInterop
        0x1040a8000 -         0x1040c7fff FirebaseSessions arm64   /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/FirebaseSessions.framework/FirebaseSessions
        0x104104000 -         0x10412bfff GoogleDataTransport arm64   /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/GoogleDataTransport.framework/GoogleDataTransport
        0x104168000 -         0x104187fff GoogleUtilities arm64  <1749d93942fe31be964b898253f921ce> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/GoogleUtilities.framework/GoogleUtilities
        0x1041b4000 -         0x1041d7fff IQKeyboardManager arm64  <1e9fc7be7b9f3719b678e6f07f9f88fd> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/IQKeyboardManager.framework/IQKeyboardManager
        0x104204000 -         0x104223fff Koloda arm64  <235b55c4c1353c218e82a49ba640ed9b> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/Koloda.framework/Koloda
        0x104254000 -         0x104267fff Promises arm64   /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/Promises.framework/Promises
        0x104288000 -         0x1042abfff TRON arm64   /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/TRON.framework/TRON
        0x1042f8000 -         0x104313fff TextFieldEffects arm64  <59572aabef133e0d959aa274d84173ea> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/TextFieldEffects.framework/TextFieldEffects
        0x10434c000 -         0x10435bfff WARangeSlider arm64  <651e5943e9dd3a8894f41325ab717310> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/WARangeSlider.framework/WARangeSlider
        0x104374000 -         0x10437bfff nanopb arm64  <34e463e7b3243c1ca2d16f0a89f311f2> /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/nanopb.framework/nanopb
        0x104388000 -         0x1043a7fff pop arm64   /private/var/containers/Bundle/Application/24D4E3B0-0D19-4963-BD91-9BF3FECEE8F5/MyApp.app/Frameworks/pop.framework/pop
        0x104d1c000 -         0x104d27fff libobjc-trampolines.dylib arm64e  <35a44678195b39c2bdd7072893564b45> /private/preboot/Cryptexes/OS/usr/lib/libobjc-trampolines.dylib
        0x186720000 -         0x186770d5f libobjc.A.dylib arm64e  <1608892e67db3f949fc291492b86c95f> /usr/lib/libobjc.A.dylib
        0x188025000 -         0x188d32fff Foundation arm64e  <6d0212cc3b9e32c9be2072989ce3acb8> /System/Library/Frameworks/Foundation.framework/Foundation
        0x191136000 -         0x19117bfff libdispatch.dylib arm64e  <7de7ec03cfb7349d9b9e8782b38f231d> /usr/lib/system/libdispatch.dylib
        0x191376000 -         0x191700fff CoreData arm64e   /System/Library/Frameworks/CoreData.framework/CoreData
        0x192754000 -         0x19276aff0 libswiftDispatch.dylib arm64e   /usr/lib/swift/libswiftDispatch.dylib
        0x194ade000 -         0x194b60fff libswift_Concurrency.dylib arm64e   /usr/lib/swift/libswift_Concurrency.dylib
        0x196cb9000 -         0x196f18fff CoreLocation arm64e  <3a46af8cb1e53941838788724a3923d9> /System/Library/Frameworks/CoreLocation.framework/CoreLocation
        0x1aedef000 -         0x1aee7299f dyld arm64e  <3060d36a16ce3c3a92583881459f5714> /usr/lib/dyld
        0x1b69f2000 -         0x1b6b72ff3 libsqlite3.dylib arm64e  <8190f926afce3a16afcd90a8d83561d5> /usr/lib/libsqlite3.dylib
        0x1d97f5000 -         0x1d982eff3 libsystem_kernel.dylib arm64e   /usr/lib/system/libsystem_kernel.dylib
        0x21192f000 -         0x21193bff3 libsystem_pthread.dylib arm64e  <3ca98e388eee3c269862c5f66aad93c0> /usr/lib/system/libsystem_pthread.dylib
        0x216805000 -         0x21681dff8 libswiftCoreLocation.dylib arm64e   /usr/lib/swift/libswiftCoreLocation.dylib

EOF

I attached a crash log with the details I can share for the moment

So, this crash log is a great example of why I always try to get a full log before trying to diagnose anything. It's very easy to focus on the threads that seem to be the source of the problem without realizing there are other concerns in play.

In this case, my biggest concern is the combination 6 threads and your main thread state:

32  MyMainModule    	0x00000001038d4064 +[MyMainModuleInitClass load] + 100 (MyMainModuleInitClass.m:32)
33  libobjc.A.dylib               	0x0000000186724714 load_images + 736 (objc-runtime-new.mm:3740)
34  dyld                          	0x00000001aedfad10 dyld4::RuntimeState::notifyObjCInit(dyld4::Loader const*) + 576 (DyldRuntimeState.cpp:2139)
35  dyld                          	0x00000001aee33908 dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array&, dyld3::Array&) const + 300 (Loader.cpp:2316)
36  dyld                          	0x00000001aee338b4 dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array&, dyld3::Array&) const + 216 (Loader.cpp:2309)
37  dyld                          	0x00000001aee352c8 dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const::$_0::operator()() const + 180 (Loader.cpp:2330)
38  dyld                          	0x00000001aee00c00 dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const + 412 (Loader.cpp:2326)
39  dyld                          	0x00000001aedf0280 dyld4::APIs::runAllInitializersForMain() + 296 (DyldAPIs.cpp:4150)
40  dyld                          	0x00000001aee04d10 dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 3404 (dyldMain.cpp:902)
41  dyld                          	0x00000001aee299f8 dyld4::start(dyld4::KernelArgs*, void*, void*)::$_0::operator()() const + 544 (dyldMain.cpp:1322)
42  dyld                          	0x00000001aee22cb0 start + 2188 (dyldMain.cpp:1299)

Your app is currently in library load time and has not yet called main. In other words, you've kicked off most of your apps functionality, including initializing system framework like CoreLocation, BEFORE your app has initialized UIKit and started it's event loop.

The systems behavior in this state is basically... undefined. Most of our framework implicitly assume that they're running "in an app" and rely on a variety of implicit configuration/state that comes from that configuration. Lots of things do "work" (which is why your app works at all), but that's basically "accidental", NOT because of any special effort on the frameworks part.

Related to that point, I also noticed that your app crashing very early in a background launch:

Role:                Non UI
...
Date/Time:           2024-11-21 14:51:03.5555 +0100
Launch Time:         2024-11-21 14:51:03.1668 +0100

A few questions about this:

  • Is that consistent across all the crash logs you've gotten do some of the logs list a different role? Particularly foreground crashes?

  • Do you what might be triggering that launch (besides CoreLocation)?

The issue here is that the process a daemon uses to launch an app into the background is intended to work something like this:

  1. The daemon asks the system to launch the app.
  2. The app is launched.
  3. The app registers itself with the system early in UIApplicationMain().
  4. The app connects "back" to the daemon as part of it's normal start up process.

Focusing on point 4, most of our background APIs have some part of the documentation that includes a statement/verbiage similar to this:

"If your app actively receives and processes location updates and terminates, it should restart those APIs upon launch in order to continue receiving updates."

The issue here is that while CoreLocation initiates your app launch, it needs your app to connect BACK to it before it can actually "do" anything with your app. It needs that connection "back" from your app both to deliver events and, more importantly, to keep your app awake to have events delivered to it.

The problem with initializing at library load time (which is what your app is doing) is that you can "flip" the order of 3 & 4. What happens after that point depends entirely on the internal details of locationd and the daemon's that manage app lifetime. In the worst case, locationd is unable to properly "manage" your app because doing so relies on internal "infrastructure" that does actually exist yet (because that infrastructure is initialized in #3).

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

CLMonitor related crash - EXC_BAD_ACCESS (SIGSEGV)
 
 
Q