Crash in Widget extension

Hi everyone!

I'm seeking help to understand crashes that, as I can see, come from the widget extension.

The brief stack trace that I can see under Xcode -> Window -> Organizer -> [My App] -> Crashes is pretty short (see attachment).

My widgets do fetch request to Core Data, but the operation is performed on the background thread and data is lightweight. I have been debugging for days, but haven't found any weak code blocks that might take too much memory or crash due to simple language issues.

Will appreciate any help!

In the crash report file, I see the following logs (highlight a few of them due to lines limit):

Incident Identifier: 62A28083-43EE-47F2-A2E0-89A1FA89744A
Hardware Model:      iPhone13,2
Process:             MyAppWidgetsExtension [28359]
Identifier:          MyAppWidgets
Version:             2.16.0 (290)
OS Version:          iPhone OS 17.4.1 (21E236)
Exception Type:  EXC_CRASH (SIGKILL)
Termination Reason: RUNNINGBOARD 0xdead10cc 

Thread 0 Crashed:
0   libsystem_kernel.dylib        	0x00000001e05c5af8 mach_msg2_trap + 8 (:-1)
1   libsystem_kernel.dylib        	0x00000001e05c5890 mach_msg2_internal + 80 (mach_msg.c:201)
2   libsystem_kernel.dylib        	0x00000001e05c57a8 mach_msg_overwrite + 436 (mach_msg.c:0)
3   libsystem_kernel.dylib        	0x00000001e05c55e8 mach_msg + 24 (mach_msg.c:323)
4   CoreFoundation                	0x00000001980a001c __CFRunLoopServiceMachPort + 160 (CFRunLoop.c:2624)
5   CoreFoundation                	0x000000019809df04 __CFRunLoopRun + 1208 (CFRunLoop.c:3007)
6   CoreFoundation                	0x000000019809d968 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420)
7   Foundation                    	0x0000000196f2c4a8 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212 (NSRunLoop.m:373)
8   Foundation                    	0x0000000196f2aff0 -[NSRunLoop(NSRunLoop) run] + 64 (NSRunLoop.m:398)
9   libxpc.dylib                  	0x00000001f40aa26c _xpc_objc_main + 336 (main.m:267)
10  libxpc.dylib                  	0x00000001f40ac7e4 _xpc_main + 64 (init.c:1294)
11  libxpc.dylib                  	0x00000001f40ac7a4 xpc_bs_main + 16 (init.c:1310)
12  BoardServices                 	0x00000001b0d38240 +[BSServicesConfiguration activateXPCService] + 68 (BSServicesConfiguration.m:113)
13  ExtensionFoundation           	0x00000001a70bbdf0 -[_EXRunningExtension resume] + 260 (EXRunningExtension.m:298)
14  ExtensionFoundation           	0x00000001a70bbc38 -[_EXRunningExtension startWithArguments:count:] + 396 (EXRunningExtension.m:269)
15  ExtensionFoundation           	0x00000001a70cfa30 EXExtensionMain + 220 (EXExtensionMain.m:34)
16  Foundation                    	0x0000000197665ed4 NSExtensionMain + 204 (NSExtensionMain.m:21)
17  dyld                          	0x00000001bb5bed84 start + 2240 (dyldMain.cpp:1298)

Thread 2:
0   libsystem_kernel.dylib        	0x00000001e05d381c guarded_pwrite_np + 8 (:-1)
1   libsqlite3.dylib              	0x00000001c1ddc158 seekAndWrite + 456 (sqlite3.c:44255)
2   libsqlite3.dylib              	0x00000001c1d95908 unixWrite + 180 (sqlite3.c:44333)
3   libsqlite3.dylib              	0x00000001c1de4574 pagerWalFrames + 868 (sqlite3.c:66940)
4   libsqlite3.dylib              	0x00000001c1d95628 sqlite3PagerCommitPhaseOne + 316 (sqlite3.c:70256)
5   libsqlite3.dylib              	0x00000001c1d85d7c sqlite3BtreeCommitPhaseOne + 172 (sqlite3.c:80934)
6   libsqlite3.dylib              	0x00000001c1d85944 vdbeCommit + 1136 (sqlite3.c:93952)
7   libsqlite3.dylib              	0x00000001c1d5ec74 sqlite3VdbeHalt + 1352 (sqlite3.c:94362)
8   libsqlite3.dylib              	0x00000001c1d7fd04 sqlite3VdbeExec + 42952 (sqlite3.c:103728)
9   libsqlite3.dylib              	0x00000001c1d74c80 sqlite3_step + 964 (sqlite3.c:97699)
10  CoreData                      	0x00000001a01ba0e0 _execute + 128 (NSSQLiteConnection.m:4573)
11  CoreData                      	0x00000001a01e5510 -[NSSQLiteConnection commitTransaction] + 596 (NSSQLiteConnection.m:3250)
12  CoreData                      	0x00000001a040aac0 _executeBatchUpdateRequest + 1216 (NSSQLCore_Functions.m:1110)
13  CoreData                      	0x00000001a030a240 -[NSSQLBatchUpdateRequestContext executeRequestCore:] + 32 (NSSQLBatchUpdateRequestContext.m:88)
14  CoreData                      	0x00000001a01c8508 -[NSSQLStoreRequestContext executeRequestUsingConnection:] + 252 (NSSQLStoreRequestContext.m:183)
15  CoreData                      	0x00000001a01c82b4 __52-[NSSQLDefaultConnectionManager handleStoreRequest:]_block_invoke + 60 (NSSQLConnectionManager.m:302)
16  CoreData                      	0x00000001a01c81ec __37-[NSSQLiteConnection performAndWait:]_block_invoke + 48 (NSSQLiteConnection.m:733)
17  libdispatch.dylib             	0x000000019ff66dd4 _dispatch_client_callout + 20 (object.m:576)
18  libdispatch.dylib             	0x000000019ff762c4 _dispatch_lane_barrier_sync_invoke_and_complete + 56 (queue.c:1100)
19  CoreData                      	0x00000001a01de8d0 -[NSSQLiteConnection performAndWait:] + 176 (NSSQLiteConnection.m:730)
20  CoreData                      	0x00000001a019d094 -[NSSQLDefaultConnectionManager handleStoreRequest:] + 248 (NSSQLConnectionManager.m:297)
21  CoreData                      	0x00000001a019cf64 -[NSSQLCoreDispatchManager routeStoreRequest:] + 228 (NSSQLCoreDispatchManager.m:60)
22  CoreData                      	0x00000001a019cd68 -[NSSQLCore dispatchRequest:withRetries:] + 172 (NSSQLCore.m:3975)
23  CoreData                      	0x00000001a01bc034 -[NSSQLCore executeRequest:withContext:error:] + 1208 (NSSQLCore.m:2951)
24  CoreData                      	0x00000001a01d06a0 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke.541 + 4156 (NSPersistentStoreCoordinator.m:2994)
25  CoreData                      	0x00000001a01cf57c -[NSPersistentStoreCoordinator _routeHeavyweightBlock:] + 264 (NSPersistentStoreCoordinator.m:641)
26  CoreData                      	0x00000001a01abc48 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 1048 (NSPersistentStoreCoordinator.m:2768)
27  CoreData                      	0x00000001a018bbdc -[NSManagedObjectContext executeRequest:error:] + 700 (NSManagedObjectContext.m:2044)
28  CoreData                      	0x00000001a0265be8 __116+[NSCKRecordMetadata batchUpdateMetadataMatchingEntityIdsAndPKs:withUpdates:inStore:withManagedObjectContext:error:]_block_invoke + 128 (NSCKRecordMetadata.m:744)
29  CoreFoundation                	0x000000019806dfb4 __NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__ + 24 (NSDictionaryHelpers.m:10)
30  CoreFoundation                	0x000000019806de2c -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 288 (NSDictionaryM.m:271)
31  CoreData                      	0x00000001a0265970 +[NSCKRecordMetadata batchUpdateMetadataMatchingEntityIdsAndPKs:


From EXC_CRASH (SIGKILL)

0xdead10cc (3735883980) — pronounced “dead lock” The operating system terminated the app because it held on to a file lock or SQLite database lock during suspension. Request additional background execution time on the main thread with beginBackgroundTask(withName:expirationHandler:). Make this request well before starting to write to the file in order to complete those operations and relinquish the lock before the app suspends. In an app extension, use beginActivity(options:reason:) to manage this work.

If this doesn’t help, can you post the code for getTimeline()?

Thanks for the reply!

Yes, I have followed this documentation: https://developer.apple.com/documentation/xcode/sigkill

And added next code snippet:

let activity = ProcessInfo.processInfo.beginActivity(options: .userInitiated, reason: "Fetching Data From CoreData In Widget Extension...")
            
defer {
    ProcessInfo.processInfo.endActivity(activity)
}

to the getTimeline() in widget extension like this:


Task {
    let activity = ProcessInfo.processInfo.beginActivity(options: .userInitiated, reason: "💜 Fetching Upcoming Tasks For Widget...")
            
defer {
    ProcessInfo.processInfo.endActivity(activity)
}
            
    /// fetching from the CoreData storage
    let data = await PersistenceController.fetchUpcomingData()
    let entries = // make entries
    let refreshAfter = // some time
    completion(entries, refreshAfter)
}

Does it look good in getTimeline()? @Engineer

Hope it will fix crashes to follow our bug-free policy!

Thanks again and I will update the ticket after we release the fix.

~ Pavel

@Engineer Hi, just checked the crash report under Xcode -> Window -> Organiser -> Crashes and the crash still happens in Widget Extension with the same error.

Am I missing something?

@Engineer Hi,

Sorry for many questions - still can't figure out why crash happens in widget extension.

I was curious, if it can be connected to the usage of NSPersistentCloudKitContainer?

Would appreciate any help of advice.

Thanks in advance!

I have the same issue and I still haven't found a solution

I have the same issue and I still haven't found a solution too

Crash in Widget extension
 
 
Q