I have a weather app that refreshes asynchronously. While I've never seen it crash myself, I do see about a crash per day in Apple's reports, and not from a specific device. The app does have a good amount of users and it refreshes every few minutes, but I have no idea what kind of percentage send reports to Apple, so don't really know how rare the crash really is. I've tried a few things, like making sure I the Async Downloader class that creates the datatask does not get destroyed etc. There are 2 kinds of reported crashes, the most common is at this code:
-(void)startDownload
{
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:fileURL] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:12];
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
if (!session || !request || ![session respondsToSelector:@selector(dataTaskWithRequest:completionHandler:)])
return;
// Stack trace points to line below crashing
self.dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {...}
// ...
}
The "defensive" if is a sanity check as the crash stack trace looks like this:
That self.dataTask is just @property NSURLSessionDataTask *dataTask;.
Any ideas on what to look into or try in order to avoid this?
I seems quite rare overall so I am wondering if it's a case of the app is getting killed by the system or something like that which causes an unclean termination. Would welcome any suggestion though.
Edit: Couldn't find how to get Xcode to show me more info from the crash dump, but of course I could just open it with a text editor and here is all the info:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread: 9
Last Exception Backtrace:
0 CoreFoundation 0x1ca108cb4 __exceptionPreprocess + 164 (NSException.m:202)
1 libobjc.A.dylib 0x1c32243d0 objc_exception_throw + 60 (objc-exception.mm:356)
2 CoreFoundation 0x1ca27dab8 -[NSObject(NSObject) doesNotRecognizeSelector:] + 136 (NSObject.m:140)
3 CoreFoundation 0x1ca11f0e8 ___forwarding___ + 1592 (NSForwarding.m:3578)
4 CoreFoundation 0x1ca185900 _CF_forwarding_prep_0 + 96 (:-1)
5 App 0x1009667cc -[AsyncDownloader startDownload] + 396 (AsyncDownloader.m:79)
Now, going to the thread that triggered this:
Thread 9 name:
Thread 9 Crashed:
0 libsystem_kernel.dylib 0x0000000208743558 __pthread_kill + 8 (:-1)
1 libsystem_pthread.dylib 0x0000000229411118 pthread_kill + 268 (pthread.c:1670)
2 libsystem_c.dylib 0x00000001d162b178 abort + 180 (abort.c:118)
3 libc++abi.dylib 0x000000022934fbf8 abort_message + 132 (:-1)
4 libc++abi.dylib 0x000000022933f444 demangling_terminate_handler() + 348 (:-1)
5 libobjc.A.dylib 0x00000001c3229ea4 _objc_terminate() + 144 (objc-exception.mm:498)
6 libc++abi.dylib 0x000000022934efbc std::__terminate(void (*)()) + 16 (:-1)
7 libc++abi.dylib 0x000000022934ef60 std::terminate() + 56 (:-1)
8 libdispatch.dylib 0x00000001d15caec0 _dispatch_client_callout + 40 (object.m:563)
9 libdispatch.dylib 0x00000001d15ce330 _dispatch_continuation_pop + 504 (queue.c:306)
10 libdispatch.dylib 0x00000001d15e1908 _dispatch_source_invoke + 1588 (source.c:961)
11 libdispatch.dylib 0x00000001d15cde6c _dispatch_queue_override_invoke + 500 (queue.c:0)
12 libdispatch.dylib 0x00000001d15dc944 _dispatch_root_queue_drain + 396 (queue.c:7051)
13 libdispatch.dylib 0x00000001d15dd158 _dispatch_worker_thread2 + 164 (queue.c:7119)
14 libsystem_pthread.dylib 0x000000022940ada0 _pthread_wqthread + 228 (pthread.c:2631)
15 libsystem_pthread.dylib 0x000000022940ab7c start_wqthread + 8 (:-1)
Thread 9 crashed with ARM Thread State (64-bit):
x0: 0x0000000000000000 x1: 0x0000000000000000 x2: 0x0000000000000000 x3: 0x0000000000000000
x4: 0x0000000229353647 x5: 0x000000016fa2acb0 x6: 0x000000000000006e x7: 0x0000000000002700
x8: 0xc5115eb4a9cc1e34 x9: 0xc5115eb5c66eae34 x10: 0x0000000000000200 x11: 0x000000000000000b
x12: 0x000000000000000b x13: 0x00000000001ff800 x14: 0x00000000000007fb x15: 0x000000009002802e
x16: 0x0000000000000148 x17: 0x000000016fa2b000 x18: 0x0000000000000000 x19: 0x0000000000000006
x20: 0x000000000001e10f x21: 0x000000016fa2b0e0 x22: 0x0000000000000110 x23: 0x0000000000000000
x24: 0x0000000000000000 x25: 0x000000016fa2b0e0 x26: 0x0000000000030008 x27: 0x0000000282e3d180
x28: 0x0000000220904c80 fp: 0x000000016fa2ac20 lr: 0x0000000229411118
sp: 0x000000016fa2ac00 pc: 0x0000000208743558 cpsr: 0x40001000
esr: 0x56000080 Address size fault
