Main Thread Checker: UI API called on a background thread: -[UIApplication delegate] - ios

Xcode 9 seems to be reporting a lot of Main thread calls to UIApplication properties. Even though the UI is not being updated this is particularly cumbersome due to the extension of logs it produces a default environment.
4 TestApp 0x0000000101c262e0 __39-[ViewController viewDidLoad]_block_invoke + 196
5 libdispatch.dylib 0x0000000102279654 _dispatch_call_block_and_release + 24
6 libdispatch.dylib 0x0000000102279614 _dispatch_client_callout + 16
7 libdispatch.dylib 0x0000000102289008 _dispatch_queue_serial_drain + 716
8 libdispatch.dylib 0x000000010227ce58 _dispatch_queue_invoke + 340
9 libdispatch.dylib 0x000000010228a1c4 _dispatch_root_queue_drain_deferred_wlh + 412
10 libdispatch.dylib 0x00000001022917fc _dispatch_workloop_worker_thread + 868
11 libsystem_pthread.dylib 0x00000001ac6771e8 _pthread_wqthread + 924
12 libsystem_pthread.dylib 0x00000001ac676e40 start_wqthread + 4

If these reporting messages confuse you uncheck them:
Edit Scheme...
Uncheck "Main Thread Checker" in Run > Diagnostics

Check also ARKit template Xcode project Main Thread Checker log console.
If UIApplication or UIApplicationDelegate method is called from another thread you can disable checking thread as in CGN answer, but it will disable this checker completely. You can also subclass what is necessary and call metod of superclass on main thread. This way you can still use Main Thread Sanitizer in other places in code

Related

AVAudioEngineImpl::IOUnitConfigurationChanged() Crash

I use AudioEngine.
In crash reports I see some random EXC_BREAKPOINT crashes with this stacktrace
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x00000001896df0e4
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [12467]
Triggered by Thread: 15
Thread 15 Crashed:
0 libdispatch.dylib 0x00000001896df0e4 __DISPATCH_WAIT_FOR_QUEUE__ + 448 (queue.c:1619)
1 libdispatch.dylib 0x00000001896dec74 _dispatch_sync_f_slow + 140 (queue.c:1732)
2 libdispatch.dylib 0x00000001896dec74 _dispatch_sync_f_slow + 140 (queue.c:1732)
3 AVFAudio 0x00000001965b11a8 -[AVAudioEngine dealloc] + 308 (AVAudioEngine.mm:406)
4 Foundation 0x0000000189ce52ac -[NSConcreteNotification dealloc] + 68 (NSNotification.m:206)
5 AVFAudio 0x00000001965b7158 invocation function for block in AVAudioEngineImpl::IOUnitConfigurationChanged() + 292 (AVAudioEngine.mm:1215)
6 libdispatch.dylib 0x00000001896de998 _dispatch_block_async_invoke2 + 104 (queue.c:525)
7 libdispatch.dylib 0x00000001896fb184 _dispatch_client_callout + 16 (object.m:495)
8 libdispatch.dylib 0x00000001896d4e8c _dispatch_continuation_pop$VARIANT$armv81 + 404 (inline_internal.h:2484)
9 libdispatch.dylib 0x00000001896e502c _dispatch_source_invoke$VARIANT$armv81 + 1232 (source.c:568)
10 libdispatch.dylib 0x00000001896d85e0 _dispatch_lane_serial_drain$VARIANT$armv81 + 260 (inline_internal.h:2525)
11 libdispatch.dylib 0x00000001896d9128 _dispatch_lane_invoke$VARIANT$armv81 + 400 (queue.c:3863)
12 libdispatch.dylib 0x00000001896e243c _dispatch_workloop_worker_thread + 576 (queue.c:6445)
13 libsystem_pthread.dylib 0x000000018974ab88 _pthread_wqthread + 276 (pthread.c:2351)
14 libsystem_pthread.dylib 0x000000018974d760 start_wqthread + 8
I can't reproduce this crash and stacktrace doesn't point to my code. Does anyone know what is cause of this crash, how this can be fixed and if it's even possible to fix?
Thanks
According to the apple documentation of AVAudioEngineConfigurationChange,
You must not release the engine during handling this notification.
Note The engine must not be deallocated from within the client's
notification handler. Callback happens on an internal dispatch queue
and can deadlock while trying to teardown the engine synchronously.
Though you didn't release at that time, It can be caused.
AVAudioEngine in iOS 11 or 12 can be stucked to notify before, then you release engine later.
There's workaround. You have to re-use the audio engine rather than re-create.

Unable to eliminate Firebase Analytics Thread warnings using Xcode 9 in Swift

After moving to Xcode 9 with an existing project I’m keep receiving warnings from the Main Thread Checker about a queue called FIRAnalyticsQueue.
I found this MTC as an awesome feature, since I’ve already resolved quite a lot threading issues with it, but unfortunately I’m not able to eliminate the one regarding to Firebase configuration.
The code that I use in the AppDelegate didFinishLaunchingWithOptions function is the following:
if FIRApp.defaultApp() == nil {
FIRApp.configure()
}
And the log that I receives after evaluating the code above:
2017-10-05 16:14:34.965 PonySugarCandyApp[17721] <Error> [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add [FIRApp configure] to your application initialization.
2017-10-05 16:14:45.283 PonySugarCandyApp[17721] <Notice> [Firebase/Analytics][I-ACS023007] Firebase Analytics v.3700000 started
2017-10-05 16:14:52.139 PonySugarCandyApp[17721] <Notice> [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled
=================================================================
Main Thread Checker: UI API called on a background thread: -[UIApplication delegate]
PID: 17721, TID: 1309471, Thread name: (none), Queue name: FIRAnalyticsQueue, QoS: 9
Backtrace:
4 PonySugarCandyApp 0x000000010c5fe721 __38+[FIRAnalytics createAppDelegateProxy]_block_invoke + 55
5 libdispatch.dylib 0x000000011337143c _dispatch_client_callout + 8
6 libdispatch.dylib 0x00000001133729c7 dispatch_once_f + 297
7 PonySugarCandyApp 0x000000010c5fd519 __47+[FIRAnalytics startWithConfiguration:options:]_block_invoke_2 + 101
8 libdispatch.dylib 0x00000001133703f7 _dispatch_call_block_and_release + 12
9 libdispatch.dylib 0x000000011337143c _dispatch_client_callout + 8
10 libdispatch.dylib 0x000000011337995b _dispatch_queue_serial_drain + 1162
11 libdispatch.dylib 0x000000011337a2df _dispatch_queue_invoke + 336
12 libdispatch.dylib 0x000000011337d1f9 _dispatch_root_queue_drain + 772
13 libdispatch.dylib 0x000000011337ce97 _dispatch_worker_thread3 + 132
14 libsystem_pthread.dylib 0x00000001138345a2 _pthread_wqthread + 1299
15 libsystem_pthread.dylib 0x000000011383407d start_wqthread + 13
(Recorded stack frame)
This has been fixed in the latest version of Firebase. Do a pod update to upgrade to Firebase 4.3.0. More details on the issue and fix at https://github.com/firebase/firebase-ios-sdk/issues/69.
I believe going to your project name and clicking edit scheme, you can go into your environment variables and add:
Name: "OS_ACTIVITY_MODE"
Value: "disable"
This should stop firebase from printing a bunch of text to your console when running your application.
This was an issue for me with the newest version of Firebase (as of 19/12/17) and this fix worked out ok.
See this Brian Voong tutorial for more information.

FMDB Crash: SEGV_MAPERR at [FMDatabaseQueue inDatabase:]

I'm using FMDB in an iOS app. Recently I have received several crash reports from Apteligent about a crash of FMDB:
0 libdispatch.dylib 0x00000001810ab120 _dispatch_main_queue_callback_4CF + 2904
! 1 myApp 0x00000001001ac840 -[FMDatabaseQueue inDatabase:] (FMDatabaseQueue.m:142)
2 myApp 0x000000010011844c +[DataBaseController insert:withObjects:] (DataBaseController.m:602)
3 myApp 0x0000000100118254 +[DataBaseController insertObjects:withObjects:] (DataBaseController.m:575)
4 myApp 0x0000000100150e80 -[SendManagementBBDD crearySalvarEnvioConSolicitud:EntidadParaEncolar:borrarTrasEnvio:] (SendManagementBBDD.m:686)
5 myApp 0x0000000100150a28 __76-[SendManagementBBDD sendEntitiesAfterDetail:OnComplete:]_block_invoke (SendManagementBBDD.m:615)
6 libdispatch.dylib 0x00000001810a55f0 _dispatch_client_callout + 12
7 libdispatch.dylib 0x00000001810b0b94 _dispatch_sync_f_invoke + 68
8 myApp 0x0000000100150404 -[SendManagementBBDD sendEntitiesAfterDetail:OnComplete:] (SendManagementBBDD.m:563)
9 myApp 0x000000010005c284 __44-[DetailVC startWork:]_block_invoke (DetailVC.m:286)
10 libdispatch.dylib 0x00000001810a5630 _dispatch_call_block_and_release + 20
11 libdispatch.dylib 0x00000001810a55f0 _dispatch_client_callout + 12
12 libdispatch.dylib 0x00000001810b3a88 _dispatch_root_queue_drain + 2136
13 libdispatch.dylib 0x00000001810b3224 _dispatch_worker_thread3 + 108
14 libsystem_pthread.dylib 0x00000001812b9470 _pthread_wqthread + 1088
15 libsystem_pthread.dylib 0x00000001812b9020 start_wqthread + 0
I access to the database from multiple threads. As the documentation says, I have a single instance of FMDatabaseQueue and I share it across all the threads of the app. I'm getting a SEGV_MAPERR crash at the method [FMDatabaseQueue inDatabase:]
This crash happens hardly ever, but I would like to resolve it.
Any ideas what is causing it?
Thank you very much.
Like your other question, this crash seems to be a part of your app code and not Crittercism SDK. If you still believe that this has been caused due to Crittercism, you can create a support ticket by sending an email to support#apteligent.com by mentioning the concerned App ID and the direct crash URL. Be noted that the email support is available for paid customers only.

com.apple.NSURLSession-work EXC_BAD_ACCESS Crash debugging

I'm seeing the following crash report, but it's not reproducible. How would I go about debugging it? Is this an AFNetworking issue? I'm using version 2.4.1.
Crashed: com.apple.NSURLSession-work
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x0000000000000000
Thread : Crashed: com.apple.NSURLSession-work
0 CoreFoundation 0x0000000184aad978 CFDictionaryGetValue + 56
1 Foundation 0x0000000185aa9300 _NSSetLongLongValueAndNotify + 72
2 Foundation 0x0000000185aa9300 _NSSetLongLongValueAndNotify + 72
3 CFNetwork 0x0000000184543468 -[__NSCFLocalSessionTask _task_onqueue_didFinish] + 472
4 CFNetwork 0x0000000184544b38 -[__NSCFLocalSessionTask connection:didFinishLoadingWithError:] + 40
5 CFNetwork 0x000000018458d030 __46-[__NSCFURLSessionConnection _task_sendFinish]_block_invoke + 136
6 libdispatch.dylib 0x0000000196a49994 _dispatch_call_block_and_release + 24
7 libdispatch.dylib 0x0000000196a49954 _dispatch_client_callout + 16
8 libdispatch.dylib 0x0000000196a540a4 _dispatch_queue_drain + 1448
9 libdispatch.dylib 0x0000000196a4ca5c _dispatch_queue_invoke + 132
10 libdispatch.dylib 0x0000000196a56318 _dispatch_root_queue_drain + 720
11 libdispatch.dylib 0x0000000196a57c4c _dispatch_worker_thread3 + 108
12 libsystem_pthread.dylib 0x0000000196c2922c _pthread_wqthread + 816
Yes, it's probably an AFNetworking bug (fixed in 2.5.0), in all likelihood. Specifically, this one:
https://github.com/AFNetworking/AFNetworking/issues/1477
If not, then it is probably something similar—a key-value observer trying to observe some aspect of a URL session task has been deallocated and didn't stop observing that task prior to being deallocated.
I got the same issue and I found it is because I was using Firebase SDK and I upgraded it to 7.0.0,(Although this issue is reported by many developers from > 6.32.1 to 7.0.0) So the firebasePerformance is causing this issue in the first place, which later caused a crash while downloading images using SDWebImage. More information about this issue is here:
firebase/firebase-ios-sdk#6734
Firebase recently fixed this and released a new version for FirebasePerformance (7.0.1) After upgrading to version 7.0.1, I wasn't able to reproduce the crash any longer.
So upgrading of FirebasePerformance SDK to 7.0.1 version worked for me.

AFNetworking crash analysis for EXC_BAD_ACCESS KERN_INVALID_ADDRESS

I'm getting crash reports of AFNetworking throwing an EXC_BAD_ACCESS KERN_INVALID_ADDRESS:
Thread : Crashed: com.apple.root.default-priority
0 libobjc.A.dylib 0x39e237fa objc_release + 9
1 MY_APP 0x0015ba63 __64-[AFHTTPRequestOperation setCompletionBlockWithSuccess:failure:]_block_invoke (AFHTTPRequestOperation.m:266)
2 MY_APP 0x00163bf7 __47-[AFURLConnectionOperation setCompletionBlock:]_block_invoke (AFURLConnectionOperation.m:301)
3 Foundation 0x3049a2a9 __103+[__NSOperationInternal _observeValueForKeyPath:ofObject:changeKind:oldValue:newValue:indexes:context:]_block_invoke96 + 12
4 libdispatch.dylib 0x3a30b0c3 _dispatch_call_block_and_release + 10
5 libdispatch.dylib 0x3a3107d9 _dispatch_root_queue_drain + 224
6 libdispatch.dylib 0x3a3109c5 _dispatch_worker_thread2 + 56
7 libsystem_pthread.dylib 0x3a43adff _pthread_wqthread + 298
I need help to understand the possible bug. This is something that happens sometimes, actually is very rare and it could be related to a timeout issue when user is using 3G (network can be disconnected while loading data).
I don't post my code because I can't find on the crash log in which file or class this crash happened and I use AFNetworking in a lot of files.
Without any code this is all conjecture but:
Something in the completion block is being accessed after it is deallocated. Commonly, this happens when a network operation isn't cancelled after a view controller is dismissed.

Resources