Reputation: 349
I need help.
I'm working on an old iOS app written in Objective-c. It was released in 2014 and now I have migrated the project to Xcode 8. After migration everything works as expected except weird crash when app is in background(not immediately but after some time). It's hard to debug because crash occurs only when device is disconnected from Xcode. I have checked device logs and it seems like it's core data crash:
Incident Identifier: BDD70C46-6573-44A7-85AB-620E6FBA207F
CrashReporter Key: c04f591f9e0cc9d1991ce10e33ebcabd56affbe6
Hardware Model: iPhone8,4
Process: myApp [17746]
Path: /private/var/containers/Bundle/Application/878DB803-1DA5-46D7-8B50-655D43A5C28D/myApp.app/myApp
Identifier: com.example.myApp
Version: 2 (1.0.2)
Code Type: ARM-64 (Native)
Role: Foreground
Parent Process: launchd [1]
Coalition: com.example.myApp [16959]
Date/Time: 2017-09-19 14:34:57.1435 +0300
Launch Time: 2017-09-19 14:31:38.0853 +0300
OS Version: iPhone OS 10.3.3 (14G60)
Report Version: 104
Exception Type: EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: Namespace <0xF>, Code 0x8badf00d
Triggered by Thread: 0
Filtered syslog:
None found
Thread 0 name: Dispatch queue: SQLQueue 0x100724310 for myApp.sqlite
Thread 0 Crashed:
0 libsqlite3.dylib 0x000000018f36d818 0x18f361000 + 51224
1 libsqlite3.dylib 0x000000018f36c9a4 0x18f361000 + 47524
2 libsqlite3.dylib 0x000000018f36c9a4 0x18f361000 + 47524
3 libsqlite3.dylib 0x000000018f36c2c4 0x18f361000 + 45764
4 libsqlite3.dylib 0x000000018f36bf24 0x18f361000 + 44836
5 CoreData 0x000000019113e0b0 -[NSSQLiteConnection prepareSQLStatement:] + 468
6 CoreData 0x000000019125f178 -[NSSQLiteConnection updateRow:forRequestContext:] + 492
7 CoreData 0x0000000191307f28 _writeChangesForSaveRequest + 1128
8 CoreData 0x0000000191309584 _executeSaveChangesRequest + 388
9 CoreData 0x00000001912ff5f0 -[NSSQLSaveChangesRequestContext executeRequestUsingConnection:] + 44
10 CoreData 0x00000001912170c4 __52-[NSSQLDefaultConnectionManager handleStoreRequest:]_block_invoke + 256
11 libdispatch.dylib 0x0000000100455a10 0x100454000 + 6672
12 libdispatch.dylib 0x00000001004625bc 0x100454000 + 58812
13 CoreData 0x0000000191216f64 -[NSSQLDefaultConnectionManager handleStoreRequest:] + 208
14 CoreData 0x00000001912d9824 -[NSSQLCoreDispatchManager routeStoreRequest:] + 272
15 CoreData 0x000000019124475c -[NSSQLCore dispatchRequest:withRetries:] + 236
16 CoreData 0x0000000191240578 -[NSSQLCore processSaveChanges:forContext:] + 200
17 CoreData 0x0000000191144f10 -[NSSQLCore executeRequest:withContext:error:] + 724
18 CoreData 0x000000019122384c __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 3492
19 CoreData 0x000000019121c0f0 -[NSPersistentStoreCoordinator _routeHeavyweightBlock:] + 276
20 CoreData 0x0000000191144adc -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 408
21 CoreData 0x000000019116597c -[NSManagedObjectContext save:] + 2548
22 myApp 0x00000001000cd0dc 0x1000c0000 + 53468
23 myApp 0x00000001000cbc24 0x1000c0000 + 48164
24 CoreLocation 0x00000001970ee828 0x1970de000 + 67624
25 CoreLocation 0x00000001970edfcc 0x1970de000 + 65484
26 CoreLocation 0x00000001970e11d8 0x1970de000 + 12760
27 CoreFoundation 0x000000018ee1930c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 20
28 CoreFoundation 0x000000018ee18b28 __CFRunLoopDoBlocks + 288
29 CoreFoundation 0x000000018ee16e1c __CFRunLoopRun + 1884
30 CoreFoundation 0x000000018ed46da4 CFRunLoopRunSpecific + 424
31 GraphicsServices 0x00000001907b1074 GSEventRunModal + 100
32 UIKit 0x0000000195001c9c UIApplicationMain + 208
33 myApp 0x00000001000e4574 0x1000c0000 + 148852
34 libdyld.dylib 0x000000018dd5559c start + 4
Thread 1 name: Dispatch queue: BKSProcessAssertionClient
Thread 1:
0 libsystem_kernel.dylib 0x000000018de47224 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000018de4709c mach_msg + 72
2 libdispatch.dylib 0x000000010046d37c 0x100454000 + 103292
3 libdispatch.dylib 0x000000010046d780 0x100454000 + 104320
4 libxpc.dylib 0x000000018df60edc xpc_connection_send_message_with_reply_sync + 196
5 BaseBoard 0x000000019095a944 -[BSXPCMessage sendSynchronouslyToConnection:error:] + 76
6 BaseBoard 0x0000000190957148 -[BSBaseXPCClient _sendMessage:withReplyHandler:waitForReply:waitDuration:] + 436
7 AssertionServices 0x00000001909a17c4 -[BKSProcessAssertionClient _assertionQueue_sendEvent:forMessageType:responseHandler:] + 136
8 AssertionServices 0x00000001909a0f78 -[BKSProcessAssertionClient sendCreateAssertion:] + 108
9 AssertionServices 0x00000001909a0968 -[BKSProcessAssertion _clientQueue_acquireAssertion] + 312
10 libdispatch.dylib 0x0000000100455a50 0x100454000 + 6736
11 libdispatch.dylib 0x0000000100455a10 0x100454000 + 6672
12 libdispatch.dylib 0x00000001004632e8 0x100454000 + 62184
13 libdispatch.dylib 0x0000000100459634 0x100454000 + 22068
14 libdispatch.dylib 0x0000000100465630 0x100454000 + 71216
15 libdispatch.dylib 0x000000010046539c 0x100454000 + 70556
16 libsystem_pthread.dylib 0x000000018df2b100 _pthread_wqthread + 1096
17 libsystem_pthread.dylib 0x000000018df2acac start_wqthread + 4
Thread 2 name: Dispatch queue: com.apple.CoreLocation.ConnectionClient.0x17013b6c0.events
Thread 2:
0 libsystem_kernel.dylib 0x000000018de47278 semaphore_timedwait_trap + 8
1 libdispatch.dylib 0x000000010047f238 0x100454000 + 176696
2 libdispatch.dylib 0x0000000100467db8 0x100454000 + 81336
3 CoreLocation 0x00000001970e1078 0x1970de000 + 12408
4 CoreLocation 0x00000001970e6118 0x1970de000 + 33048
5 CoreLocation 0x00000001970e5f18 0x1970de000 + 32536
6 CoreLocation 0x0000000197131e88 0x1970de000 + 343688
7 CoreLocation 0x000000019712e4f0 0x1970de000 + 328944
8 CoreLocation 0x000000019712e414 0x1970de000 + 328724
9 CoreLocation 0x000000019712fa80 0x1970de000 + 334464
10 libxpc.dylib 0x000000018df5f84c _xpc_connection_call_event_handler + 68
11 libxpc.dylib 0x000000018df5d358 _xpc_connection_mach_event + 1448
12 libdispatch.dylib 0x0000000100455ae0 0x100454000 + 6880
13 libdispatch.dylib 0x00000001004599d8 0x100454000 + 23000
14 libdispatch.dylib 0x0000000100463128 0x100454000 + 61736
15 libdispatch.dylib 0x0000000100458da0 0x100454000 + 19872
16 libdispatch.dylib 0x0000000100463128 0x100454000 + 61736
17 libdispatch.dylib 0x0000000100459634 0x100454000 + 22068
18 libdispatch.dylib 0x0000000100463128 0x100454000 + 61736
19 libdispatch.dylib 0x0000000100459634 0x100454000 + 22068
20 libdispatch.dylib 0x0000000100464358 0x100454000 + 66392
21 libdispatch.dylib 0x000000010046c57c 0x100454000 + 99708
22 libsystem_pthread.dylib 0x000000018df2afbc _pthread_wqthread + 772
23 libsystem_pthread.dylib 0x000000018df2acac start_wqthread + 4
Thread 3 name: com.apple.uikit.eventfetch-thread
Thread 3:
0 libsystem_kernel.dylib 0x000000018de47224 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000018de4709c mach_msg + 72
2 CoreFoundation 0x000000018ee18e90 __CFRunLoopServiceMachPort + 192
3 CoreFoundation 0x000000018ee16ae4 __CFRunLoopRun + 1060
4 CoreFoundation 0x000000018ed46da4 CFRunLoopRunSpecific + 424
5 Foundation 0x000000018f861db4 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 304
6 Foundation 0x000000018f882b84 -[NSRunLoop(NSRunLoop) runUntilDate:] + 96
7 UIKit 0x000000019598b830 -[UIEventFetcher threadMain] + 136
8 Foundation 0x000000018f95f318 __NSThread__start__ + 996
9 libsystem_pthread.dylib 0x000000018df2d68c _pthread_body + 240
10 libsystem_pthread.dylib 0x000000018df2d59c _pthread_body + 0
11 libsystem_pthread.dylib 0x000000018df2acb4 thread_start + 4
Thread 4:
0 libsystem_pthread.dylib 0x000000018df2aca8 start_wqthread + 0
Thread 5 name: com.apple.NSURLConnectionLoader
Thread 5:
0 libsystem_kernel.dylib 0x000000018de47224 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000018de4709c mach_msg + 72
2 CoreFoundation 0x000000018ee18e90 __CFRunLoopServiceMachPort + 192
3 CoreFoundation 0x000000018ee16ae4 __CFRunLoopRun + 1060
4 CoreFoundation 0x000000018ed46da4 CFRunLoopRunSpecific + 424
5 CFNetwork 0x000000018f553df4 +[NSURLConnection(Loader) _resourceLoadLoop:] + 404
6 Foundation 0x000000018f95f318 __NSThread__start__ + 996
7 libsystem_pthread.dylib 0x000000018df2d68c _pthread_body + 240
8 libsystem_pthread.dylib 0x000000018df2d59c _pthread_body + 0
9 libsystem_pthread.dylib 0x000000018df2acb4 thread_start + 4
Thread 6 name: GAIThread
Thread 6:
0 libsystem_kernel.dylib 0x000000018de47224 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000018de4709c mach_msg + 72
2 CoreFoundation 0x000000018ee18e90 __CFRunLoopServiceMachPort + 192
3 CoreFoundation 0x000000018ee16ae4 __CFRunLoopRun + 1060
4 CoreFoundation 0x000000018ed46da4 CFRunLoopRunSpecific + 424
5 Foundation 0x000000018f861db4 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 304
6 Foundation 0x000000018f8b6704 -[NSRunLoop(NSRunLoop) run] + 88
7 myApp 0x0000000100120398 0x1000c0000 + 394136
8 Foundation 0x000000018f95f318 __NSThread__start__ + 996
9 libsystem_pthread.dylib 0x000000018df2d68c _pthread_body + 240
10 libsystem_pthread.dylib 0x000000018df2d59c _pthread_body + 0
11 libsystem_pthread.dylib 0x000000018df2acb4 thread_start + 4
Thread 7:
0 libsystem_pthread.dylib 0x000000018df2aca8 start_wqthread + 0
Thread 8:
0 libsystem_pthread.dylib 0x000000018df2aca8 start_wqthread + 0
But in major cases crash report looks like:
Incident Identifier: D5D6C3C6-7EB7-4E2C-901C-7203943BD722
CrashReporter Key: c04f591f9e0cc9d1991ce10e33ebcabd56affbe6
Hardware Model: iPhone8,4
Process: myApp [17444]
Path: /private/var/containers/Bundle/Application/93AB2A15-0C65-47D5-BE24-FB298DC396E0/myApp.app/myApp
Identifier: com.example.myApp
Version: 2 (1.0.2)
Code Type: ARM-64 (Native)
Role: Foreground
Parent Process: launchd [1]
Coalition: com.example.myApp [16449]
Date/Time: 2017-09-19 12:41:45.3051 +0300
Launch Time: 2017-09-19 12:24:22.7861 +0300
OS Version: iPhone OS 10.3.3 (14G60)
Report Version: 104
Exception Type: EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: Namespace <0xF>, Code 0x8badf00d
Triggered by Thread: 0
Filtered syslog:
None found
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x000000018de47224 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000018de4709c mach_msg + 72
2 CoreFoundation 0x000000018ee18e90 __CFRunLoopServiceMachPort + 192
3 CoreFoundation 0x000000018ee16ae4 __CFRunLoopRun + 1060
4 CoreFoundation 0x000000018ed46da4 CFRunLoopRunSpecific + 424
5 GraphicsServices 0x00000001907b1074 GSEventRunModal + 100
6 UIKit 0x0000000195001c9c UIApplicationMain + 208
7 myApp 0x0000000100031bb8 0x10000c000 + 154552
8 libdyld.dylib 0x000000018dd5559c start + 4
Thread 1 name: com.apple.uikit.eventfetch-thread
Thread 1:
0 libsystem_kernel.dylib 0x000000018de47224 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000018de4709c mach_msg + 72
2 CoreFoundation 0x000000018ee18e90 __CFRunLoopServiceMachPort + 192
3 CoreFoundation 0x000000018ee16ae4 __CFRunLoopRun + 1060
4 CoreFoundation 0x000000018ed46da4 CFRunLoopRunSpecific + 424
5 Foundation 0x000000018f861db4 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 304
6 Foundation 0x000000018f882b84 -[NSRunLoop(NSRunLoop) runUntilDate:] + 96
7 UIKit 0x000000019598b830 -[UIEventFetcher threadMain] + 136
8 Foundation 0x000000018f95f318 __NSThread__start__ + 996
9 libsystem_pthread.dylib 0x000000018df2d68c _pthread_body + 240
10 libsystem_pthread.dylib 0x000000018df2d59c _pthread_body + 0
11 libsystem_pthread.dylib 0x000000018df2acb4 thread_start + 4
Thread 2 name: com.twitter.crashlytics.ios.MachExceptionServer
Thread 2:
0 libsystem_kernel.dylib 0x000000018de47224 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000018de4709c mach_msg + 72
2 myApp 0x000000010008d6a0 0x10000c000 + 530080
3 libsystem_pthread.dylib 0x000000018df2d68c _pthread_body + 240
4 libsystem_pthread.dylib 0x000000018df2d59c _pthread_body + 0
5 libsystem_pthread.dylib 0x000000018df2acb4 thread_start + 4
Thread 3 name: com.apple.NSURLConnectionLoader
Thread 3:
0 libsystem_kernel.dylib 0x000000018de47224 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000018de4709c mach_msg + 72
2 CoreFoundation 0x000000018ee18e90 __CFRunLoopServiceMachPort + 192
3 CoreFoundation 0x000000018ee16ae4 __CFRunLoopRun + 1060
4 CoreFoundation 0x000000018ed46da4 CFRunLoopRunSpecific + 424
5 CFNetwork 0x000000018f553df4 +[NSURLConnection(Loader) _resourceLoadLoop:] + 404
6 Foundation 0x000000018f95f318 __NSThread__start__ + 996
7 libsystem_pthread.dylib 0x000000018df2d68c _pthread_body + 240
8 libsystem_pthread.dylib 0x000000018df2d59c _pthread_body + 0
9 libsystem_pthread.dylib 0x000000018df2acb4 thread_start + 4
Thread 4 name: GAIThread
Thread 4:
0 libsystem_kernel.dylib 0x000000018de47224 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000018de4709c mach_msg + 72
2 CoreFoundation 0x000000018ee18e90 __CFRunLoopServiceMachPort + 192
3 CoreFoundation 0x000000018ee16ae4 __CFRunLoopRun + 1060
4 CoreFoundation 0x000000018ed46da4 CFRunLoopRunSpecific + 424
5 Foundation 0x000000018f861db4 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 304
6 Foundation 0x000000018f8b6704 -[NSRunLoop(NSRunLoop) run] + 88
7 myApp 0x000000010006d9dc 0x10000c000 + 399836
8 Foundation 0x000000018f95f318 __NSThread__start__ + 996
9 libsystem_pthread.dylib 0x000000018df2d68c _pthread_body + 240
10 libsystem_pthread.dylib 0x000000018df2d59c _pthread_body + 0
11 libsystem_pthread.dylib 0x000000018df2acb4 thread_start + 4
Thread 5:
0 libsystem_pthread.dylib 0x000000018df2aca8 start_wqthread + 0
Thread 6:
0 libsystem_pthread.dylib 0x000000018df2aca8 start_wqthread + 0
Thread 7:
0 libsystem_pthread.dylib 0x000000018df2aca8 start_wqthread + 0
Thread 8:
0 libsystem_pthread.dylib 0x000000018df2aca8 start_wqthread + 0
Thread 9:
0 libsystem_pthread.dylib 0x000000018df2aca8 start_wqthread + 0
Maybe someone had a similar issue and have some suggestions?
Upvotes: 0
Views: 3125
Reputation: 2475
One thing that's odd is that you say this happens in the background, but the crashes are happening when the app is in the foreground as far as the system is concerned:
Role: Foreground
So, that's confusing.
Just wild guessing, I'd look at things like memory corruption/using released objects (especially if this is non-ARC code), async code like networking requests or timer callbacks jumping into released code, doing things like UI on a thread that's not the main thread (if you can run under Xcode 9, the runtime thread diagnostics will help a lot with this.) Even with Xc8, look at your project's scheme and the memory debugging options available under the Run configuration. Those could help.
Check out the running system log on the device. You don't need to be debugging with Xcode to see that. Just go to the Devices window and the system console will be near the bottom. You may need to reveal it. That system log may give a clue.
If you're using manual retain/release, double check any code that gets hit in the time frame of the crash. Keep in mind that those types of crashes happen after the problem occurs, so where you see the crash may have little bearing on where the actual problem is, and the crash location may fluctuate, especially on different devices.
Maybe diff the pre-Xcode 8 code and the current code to double-check any changes you've made. My guess is that you introduced a memory issue when updating the code for Xcode 8.
UPDATE:
Sorry, just noticed the termination reason.
This may help:
The exception code 0x8badf00d indicates that an application has been terminated by iOS because a watchdog timeout occurred. The application took too long to launch, terminate, or respond to system events. One common cause of this is doing synchronous networking on the main thread. Whatever operation is on Thread 0: needs to be moved to a background thread, or processed differently, so that it does not block the main thread.
Make sure as you're going into the background you're not doing anything that will take a long time, use a background task if needed, and don't do anything like OpenGL calls from the background. Since the crash report says you're in the Foreground, I wonder if you're taking too long going into the background and Springboard is killing your app. The system log will confirm that.
Upvotes: 4