Main thread deadlocked.

There are two scenarios when the main thread gets deadlocked in the app. One of them happens on incoming call, facilitated by CallKit. Can anyone make any sense from this thread backtrace?

* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
 * frame #0: 0x00000001bba510e8 libsystem_kernel.dylib`__semwait_signal + 8
  frame #1: 0x000000018c9a28ac libsystem_c.dylib`nanosleep + 212
  frame #2: 0x000000019968ef4c libc++.1.dylib`std::__1::this_thread::sleep_for(std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > const&) + 80
  frame #3: 0x0000000199ee0bcc libAudioToolboxUtility.dylib`caulk::concurrent::guarded_lookup_hash_table<unsigned int, BaseOpaqueObject*, (caulk::concurrent::guarded_lookup_hash_table_options)0>::remove(unsigned int) + 180
  frame #4: 0x0000000199ee3bdc libAudioToolboxUtility.dylib`BaseOpaqueObject::~BaseOpaqueObject() + 48
  frame #5: 0x00000001c001a440 libEmbeddedSystemAUs.dylib`AURemoteIO::~AURemoteIO() + 264
  frame #6: 0x00000001c00238d0 libEmbeddedSystemAUs.dylib`ausdk::ComponentBase::AP_Close(void*) + 64
  frame #7: 0x000000019406e354 AudioToolboxCore`AudioComponentInstanceDispose + 60
  frame #8: 0x00000001159abba0 UnityFramework`FMOD::OutputCoreAudio::reset(bool, bool) + 472
  frame #9: 0x0000000183c685f8 Foundation`-[__NSObserver _doit:] + 316
  frame #10: 0x0000000182518c5c CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
  frame #11: 0x00000001825ad564 CoreFoundation`___CFXRegistrationPost_block_invoke + 48
  frame #12: 0x0000000182582b44 CoreFoundation`_CFXRegistrationPost + 416
  frame #13: 0x000000018252d764 CoreFoundation`_CFXNotificationPost + 696
  frame #14: 0x0000000183c4ec98 Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 92
  frame #15: 0x000000018b06d66c AudioSession`-[AVAudioSession privateInterruptionWithInfo:] + 1892
  frame #16: 0x000000018b06e2e4 AudioSession`invocation function for block in avfaudio::AVAudioSessionPropertyListener(void*, unsigned int, unsigned int, void const*) + 52
  frame #17: 0x000000018224d2ec libdispatch.dylib`_dispatch_call_block_and_release + 24
  frame #18: 0x000000018224e2f0 libdispatch.dylib`_dispatch_client_callout + 16
  frame #19: 0x000000018222f6a4 libdispatch.dylib`_dispatch_main_queue_callback_4CF$VARIANT$armv81 + 904
  frame #20: 0x000000018253d7f8 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
  frame #21: 0x00000001824fb0f8 CoreFoundation`__CFRunLoopRun + 2528
  frame #22: 0x000000018250dd8c CoreFoundation`CFRunLoopRunSpecific + 572
  frame #23: 0x000000019c61a9a0 GraphicsServices`GSEventRunModal + 160
  frame #24: 0x0000000184d42fa8 UIKitCore`-[UIApplication _run] + 1080
  frame #25: 0x0000000184ad722c UIKitCore`UIApplicationMain + 2060
  frame #26: 0x0000000114043928 UnityFramework`-[UnityFramework runUIApplicationMainWithArgc:argv:] + 108
  frame #27: 0x0000000100ee0024 Kinoo`main(argc=<unavailable>, argv=<unavailable>) at main.mm:26:9 [opt]
  frame #28: 0x0000000101518190 dyld`start + 444

There are two scenarios when the main thread gets deadlocked in the app.

Please post a full Apple crash report for this.

See Posting a Crash Report for hints on how best to do that.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hi, eskimo. Here is the abbreviated generated log due to character limit. Please let me know if the rest is also needed to paint a clearer picture.

Incident Identifier: 1D590187-852E-40DF-BA93-4052A570E2E8
CrashReporter Key:   27c27ee0e28ce9f2499a93fd88daf8245c891394
Hardware Model:      iPhone10,3
Process:             Kinoo [25894]
Path:                /private/var/containers/Bundle/Application/D7FFFA09-F4AF-4568-A67E-8BA5454C1E3F/Kinoo.app/Kinoo
Identifier:          family.kinoo.app
Version:             9.9 (101)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           family.kinoo.app [4716]

Date/Time:           2021-11-10 08:57:32.0389 -0500
Launch Time:         2021-11-10 08:52:46.9178 -0500
OS Version:          iPhone OS 15.0.2 (19A404)
Release Type:        User
Baseband Version:    7.02.00
Report Version:      104

Exception Type:  EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Termination Reason: FRONTBOARD; [2343432205]
<RBSTerminateContext| domain:10 code:0x8BADF00D explanation:scene-update watchdog transgression: application<family.kinoo.app>:25894 exhausted real (wall clock) time allowance of 10.00 seconds
ProcessVisibility: Foreground
ProcessState: Running
WatchdogEvent: scene-update
WatchdogVisibility: Background
WatchdogCPUStatistics: (
"Elapsed total CPU time (seconds): 11.840 (user 11.840, system 0.000), 18% CPU",
"Elapsed application CPU time (seconds): 1.986, 3% CPU"
) reportType:CrashLog maxTerminationResistance:Interactive>

Triggered by Thread:  0

Thread 0 name:   Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib        	       0x1bba510e8 0x1bba50000 + 4328
1   libsystem_c.dylib             	       0x18c9a28ac 0x18c99e000 + 18604
2   libc++.1.dylib                	       0x19968ef4c 0x19967a000 + 85836
3   libAudioToolboxUtility.dylib  	       0x199ee0bcc 0x199edf000 + 7116
4   libAudioToolboxUtility.dylib  	       0x199ee3bdc 0x199edf000 + 19420
5   libEmbeddedSystemAUs.dylib    	       0x1c001a440 0x1bfffc000 + 123968
6   libEmbeddedSystemAUs.dylib    	       0x1c00238d0 0x1bfffc000 + 162000
7   AudioToolboxCore              	       0x19406e354 0x194057000 + 95060
8   UnityFramework                	       0x114347ba0 0x1129c8000 + 26737568
9   Foundation                    	       0x183c685f8 0x183c35000 + 210424
10  CoreFoundation                	       0x182518c5c 0x1824f0000 + 167004
11  CoreFoundation                	       0x1825ad564 0x1824f0000 + 775524
12  CoreFoundation                	       0x182582b44 0x1824f0000 + 600900
13  CoreFoundation                	       0x18252d764 0x1824f0000 + 251748
14  Foundation                    	       0x183c4ec98 0x183c35000 + 105624
15  AudioSession                  	       0x18b06d66c 0x18b062000 + 46700
16  AudioSession                  	       0x18b06e2e4 0x18b062000 + 49892
17  libdispatch.dylib             	       0x18224d2ec 0x1821ea000 + 406252
18  libdispatch.dylib             	       0x18224e2f0 0x1821ea000 + 410352
19  libdispatch.dylib             	       0x18222f6a4 0x1821ea000 + 284324
20  CoreFoundation                	       0x18253d7f8 0x1824f0000 + 317432
21  CoreFoundation                	       0x1824fb0f8 0x1824f0000 + 45304
22  CoreFoundation                	       0x18250dd8c 0x1824f0000 + 122252
23  GraphicsServices              	       0x19c61a9a0 0x19c619000 + 6560
24  UIKitCore                     	       0x184d42fa8 0x184855000 + 5169064
25  UIKitCore                     	       0x184ad722c 0x184855000 + 2630188
26  UnityFramework                	       0x1129df928 0x1129c8000 + 96552
27  Kinoo                         	       0x102cb8024 0x102cb0000 + 32804
28  dyld                          	       0x1036dc190 0x1036c4000 + 98704

Thread 1:
0   libsystem_pthread.dylib       	       0x1dbe6aa9c 0x1dbe6a000 + 2716

Thread 2 name:  Profiler.Dispatcher
Thread 2:
0   libsystem_kernel.dylib        	       0x1bba50bac 0x1bba50000 + 2988
1   libdispatch.dylib             	       0x18221d9cc 0x1821ea000 + 211404
2   libdispatch.dylib             	       0x18221e00c 0x1821ea000 + 213004
3   UnityFramework                	       0x114038bb0 0x1129c8000 + 23530416
4   UnityFramework                	       0x114003460 0x1129c8000 + 23311456
5   UnityFramework                	       0x113a81214 0x1129c8000 + 17535508
6   UnityFramework                	       0x113a80b00 0x1129c8000 + 17533696
7   UnityFramework                	       0x113a51c5c 0x1129c8000 + 17341532
8   libsystem_pthread.dylib       	       0x1dbe6c458 0x1dbe6a000 + 9304
9   libsystem_pthread.dylib       	       0x1dbe6aab0 0x1dbe6a000 + 2736

Thread 3 name:  com.apple.uikit.eventfetch-thread
Thread 3:
0   libsystem_kernel.dylib        	       0x1bba50b70 0x1bba50000 + 2928
1   libsystem_kernel.dylib        	       0x1bba51194 0x1bba50000 + 4500
2   CoreFoundation                	       0x1824f6ad0 0x1824f0000 + 27344
3   CoreFoundation                	       0x1824fabb8 0x1824f0000 + 43960
4   CoreFoundation                	       0x18250dd8c 0x1824f0000 + 122252
5   Foundation                    	       0x183c4cb6c 0x183c35000 + 97132
6   Foundation                    	       0x183c8bd6c 0x183c35000 + 355692
7   UIKitCore                     	       0x184cc0950 0x184855000 + 4634960
8   Foundation                    	       0x183c9964c 0x183c35000 + 411212
9   libsystem_pthread.dylib       	       0x1dbe6c458 0x1dbe6a000 + 9304
10  libsystem_pthread.dylib       	       0x1dbe6aab0 0x1dbe6a000 + 2736

Thread 4 name:  JavaScriptCore bmalloc scavenger
Thread 4:
0   libsystem_kernel.dylib        	       0x1bba51550 0x1bba50000 + 5456
1   libsystem_pthread.dylib       	       0x1dbe6b96c 0x1dbe6a000 + 6508
2   libc++.1.dylib                	       0x1996832b8 0x19967a000 + 37560
3   JavaScriptCore                	       0x18da75fd8 0x18ca6c000 + 16818136
4   JavaScriptCore                	       0x18da7aa94 0x18ca6c000 + 16837268
5   JavaScriptCore                	       0x18da7a448 0x18ca6c000 + 16835656
6   JavaScriptCore                	       0x18da7bae8 0x18ca6c000 + 16841448
7   libsystem_pthread.dylib       	       0x1dbe6c458 0x1dbe6a000 + 9304
8   libsystem_pthread.dylib       	       0x1dbe6aab0 0x1dbe6a000 + 2736

I am including a screenshot of Instruments, if that helps.

We always need the full report. The attachment feature when creating a post is the best way to do this. Also, this log is not symbolicated. A fully symbolicated log is much more useful than the log in this state.

Based on what we have right now, we can determine the following:

code:0x8BADF00D explanation:scene-update watchdog

Your app was terminated for hanging the main thread for too long. I suspect you already know this, as you started this post with this observation:

* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
 * frame #0: 0x00000001bba510e8 libsystem_kernel.dylib`__semwait_signal + 8
  frame #1: 0x000000018c9a28ac libsystem_c.dylib`nanosleep + 212
  frame #2: 0x000000019968ef4c libc++.1.dylib`std::__1::this_thread::sleep_for(std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > const&) + 80
  frame #3: 0x0000000199ee0bcc libAudioToolboxUtility.dylib`caulk::concurrent::guarded_lookup_hash_table<unsigned int, BaseOpaqueObject*, (caulk::concurrent::guarded_lookup_hash_table_options)0>::remove(unsigned int) + 180
  frame #4: 0x0000000199ee3bdc libAudioToolboxUtility.dylib`BaseOpaqueObject::~BaseOpaqueObject() + 48
  frame #5: 0x00000001c001a440 libEmbeddedSystemAUs.dylib`AURemoteIO::~AURemoteIO() + 264
  frame #6: 0x00000001c00238d0 libEmbeddedSystemAUs.dylib`ausdk::ComponentBase::AP_Close(void*) + 64
  frame #7: 0x000000019406e354 AudioToolboxCore`AudioComponentInstanceDispose + 60
  frame #8: 0x00000001159abba0 UnityFramework`FMOD::OutputCoreAudio::reset(bool, bool) + 472

You can see that the main thread is dealing with a semaphore related to audio, where objects are being destroyed. If we had all of the threads and a fully symbolicated log, you might be able to see related activity on background threads as additional insightful information. However, the last frame here, plus other threads in the partial report, shows that Unity is in charge of managing your audio code, and so you should continue your investigation of this watchdog termination with their support.

Thank you.

Hi, there are similar problems in our company's Unity game app. Here is a crash log which is symbolicated. We suspect that there is a deadlock between AVAudioSession Notify Thread and main thread. And we don't know how synchronization mechanism works in InterruptionListener and _AudioComponentInstanceDispose. Thank you.

Crash log:

Brief infos are below:

Thread 0 name:  com.apple.main-thread
Thread 0: Crashed
0   libsystem_kernel.dylib          0x00000001be5da0e8 ___semwait_signal (in libsystem_kernel.dylib) + 8
1   libsystem_c.dylib               0x000000019008f8a8 _nanosleep (in libsystem_c.dylib) + 208
2   libc++.1.dylib                  0x000000019cd7bf48 std::__1::this_thread::sleep_for(std::__1::chrono::duration<long long, std::__1::ratio<(long)1, (long)1000000000> > const&) (in libc++.1.dylib) + 76
3   libAudioToolboxUtility.dylib    0x000000019d5cdbc8 caulk::concurrent::guarded_lookup_hash_table<unsigned int, BaseOpaqueObject*, (caulk::concurrent::guarded_lookup_hash_table_options)0>::remove(unsigned int) (in libAudioToolboxUtility.dylib) + 176
4   libAudioToolboxUtility.dylib    0x000000019d5d0bd8 BaseOpaqueObject::~BaseOpaqueObject() (in libAudioToolboxUtility.dylib) + 44
5   libEmbeddedSystemAUs.dylib      0x00000001c2ba343c AURemoteIO::~AURemoteIO() (in libEmbeddedSystemAUs.dylib) + 260
6   libEmbeddedSystemAUs.dylib      0x00000001c2bac8cc ausdk::ComponentBase::AP_Close(void*) (in libEmbeddedSystemAUs.dylib) + 60
7   AudioToolboxCore                0x000000019775b350 _AudioComponentInstanceDispose (in AudioToolboxCore) + 56
8   game                          0x0000000105b93f60 FMOD::OutputCoreAudio::reset(bool, bool) (in game) + 168
9   Foundation                      0x00000001873555f4 -[__NSObserver _doit:] (in Foundation) + 312
10  CoreFoundation                  0x0000000185c05c58 ___CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ (in CoreFoundation) + 16
11  CoreFoundation                  0x0000000185c9a560 ____CFXRegistrationPost_block_invoke (in CoreFoundation) + 44
12  CoreFoundation                  0x0000000185c6fb40 __CFXRegistrationPost (in CoreFoundation) + 412
13  CoreFoundation                  0x0000000185c1a760 __CFXNotificationPost (in CoreFoundation) + 692
14  Foundation                      0x000000018733bc94 -[NSNotificationCenter postNotificationName:object:userInfo:] (in Foundation) + 88
15  AudioSession                    0x000000018e75a668 -[AVAudioSession privateInterruptionWithInfo:] (in AudioSession) + 1888
16  AudioSession                    0x000000018e75b2e0 invocation function for block in avfaudio::AVAudioSessionPropertyListener(void*, unsigned int, unsigned int, void const*) (in AudioSession) + 48
17  libdispatch.dylib               0x000000018593a2e8 __dispatch_call_block_and_release (in libdispatch.dylib) + 20
18  libdispatch.dylib               0x000000018593b2ec __dispatch_client_callout (in libdispatch.dylib) + 12
19  libdispatch.dylib               0x00000001858e799c __dispatch_main_queue_callback_4CF$VARIANT$mp (in libdispatch.dylib) + 932
20  CoreFoundation                  0x0000000185c2a7f4 ___CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ (in CoreFoundation) + 8
21  CoreFoundation                  0x0000000185be80f4 ___CFRunLoopRun (in CoreFoundation) + 2524
22  CoreFoundation                  0x0000000185bfad88 _CFRunLoopRunSpecific (in CoreFoundation) + 568
23  GraphicsServices                0x000000019fd0799c _GSEventRunModal (in GraphicsServices) + 156
24  UIKitCore                       0x000000018842ffa4 -[UIApplication _run] (in UIKitCore) + 1076
25  UIKitCore                       0x00000001881c4228 _UIApplicationMain (in UIKitCore) + 2056
26  game                          0x0000000104ba16ec main (in game) (main.mm:33)
27  dyld                            0x000000010918818c start (in dyld) + 440

Thread 27 name:  AVAudioSession Notify Thread
Thread 27: 
0   libsystem_kernel.dylib          0x00000001be5dabbc ___psynch_mutexwait (in libsystem_kernel.dylib) + 8
1   libsystem_pthread.dylib         0x00000001de719664 __pthread_mutex_firstfit_lock_wait (in libsystem_pthread.dylib) + 76
2   libsystem_pthread.dylib         0x00000001de71fa2c __pthread_mutex_firstfit_lock_slow$VARIANT$mp (in libsystem_pthread.dylib) + 300
3   libc++.1.dylib                  0x000000019cd72010 std::__1::recursive_mutex::lock() (in libc++.1.dylib) + 8
4   libEmbeddedSystemAUs.dylib      0x00000001c2c22854 InterruptionListener(void*, unsigned int, unsigned int, void const*) (in libEmbeddedSystemAUs.dylib) + 84
5   AudioToolbox                    0x000000018fd179b0 AudioSessionPropertyListeners::CallPropertyListeners(unsigned int, unsigned int, void const*) (in AudioToolbox) + 552
6   AudioToolbox                    0x000000018fd84d9c HandleAudioSessionCFTypePropertyChangedMessage(unsigned int, unsigned int, void*, unsigned int) (in AudioToolbox) + 1052
7   AudioToolbox                    0x000000018fd84564 ProcessDeferredMessage(unsigned int, __CFData const*, unsigned int, unsigned int) (in AudioToolbox) + 1976
8   AudioToolbox                    0x000000018fd83a64 _ASCallbackReceiver_AudioSessionPingMessage (in AudioToolbox) + 580
9   AudioToolbox                    0x000000018fdfa7f4 __XAudioSessionPingMessage (in AudioToolbox) + 40
10  libAudioToolboxUtility.dylib    0x000000019d5ce250 _mshMIGPerform (in libAudioToolboxUtility.dylib) + 252
11  CoreFoundation                  0x0000000185c27458 ___CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ (in CoreFoundation) + 52
12  CoreFoundation                  0x0000000185c2aa48 ___CFRunLoopDoSource1 (in CoreFoundation) + 584
13  CoreFoundation                  0x0000000185be805c ___CFRunLoopRun (in CoreFoundation) + 2372
14  CoreFoundation                  0x0000000185bfad88 _CFRunLoopRunSpecific (in CoreFoundation) + 568
15  AudioSession                    0x000000018e754d78 CADeprecated::GenericRunLoopThread::Entry(void*) (in AudioSession) + 152
16  AudioSession                    0x000000018e75e0a8 CADeprecated::CAPThread::Entry(CADeprecated::CAPThread*) (in AudioSession) + 84
17  libsystem_pthread.dylib         0x00000001de718454 __pthread_start (in libsystem_pthread.dylib) + 112
18  libsystem_pthread.dylib         0x00000001de716aac _thread_start (in libsystem_pthread.dylib) + 4

Main thread deadlocked.
 
 
Q