iOS Crash on start up

We’ve been having this crash for weeks now and we can’t seem to find the issue. Might not be directly Unity related but we’re out of ideas for the moment. I believe we have the same crash on Android too but with a different (and shorter) stack trace.

Stack trace from Firebase:

Crashed: Thread
0  ourgamename                    0x103a2f0a0 il2cpp::os::FastMutex::Lock() + 64 (Mutex.cpp:64)
1  ourgamename                    0x103a4f484 il2cpp::vm::Thread::SetState(Il2CppThread*, il2cpp::vm::ThreadState) + 560 (il2cpp-object-internals.h:560)
2  ourgamename                    0x103a4fb68 il2cpp::vm::ThreadStart(void*) + 698 (Thread.cpp:698)
3  ourgamename                    0x103a2eb34 il2cpp::os::Thread::RunWrapper(void*) + 176 (Thread.cpp:176)
4  ourgamename                    0x103a30df0 il2cpp::os::ThreadImpl::ThreadStartWrapper(void*) + 106 (ThreadImpl.cpp:106)
5  libsystem_pthread.dylib        0x19d3891ec _pthread_start + 124
6  libsystem_pthread.dylib        0x19d38caec thread_start + 8

This happens to 7% of our users. Any ideas would be highly appreciated.

Do you have access to the stack traces from other threads when this crash happens?

Yeah, there’s like 40 other threads I can read.

I’ll paste some I think can be interesting.

com.apple.main-thread
0  ourgamename                    0x103a2538c il2cpp::icalls::mscorlib::System::Threading::Interlocked::Exchange(int*, int) + 87 (AtomicImpl-c-api.h:87)
1  ourgamename                    0x104a6cc48 grpc_core::Resolver::ShutdownAndUnrefLocked(void*, grpc_error*) + 16285276
2  ourgamename                    0x104a6dfa8 grpc_core::Resolver::ShutdownAndUnrefLocked(void*, grpc_error*) + 16290236
3  ourgamename                    0x104a6f4e0 grpc_core::Resolver::ShutdownAndUnrefLocked(void*, grpc_error*) + 16295668
4  ourgamename                    0x104a6f9ec grpc_core::Resolver::ShutdownAndUnrefLocked(void*, grpc_error*) + 16296960
5  ourgamename                    0x1046a1498 grpc_core::Resolver::ShutdownAndUnrefLocked(void*, grpc_error*) + 12306092
6  ourgamename                    0x1046b83cc grpc_core::Resolver::ShutdownAndUnrefLocked(void*, grpc_error*) + 12400096
7  ourgamename                    0x10469ee84 grpc_core::Resolver::ShutdownAndUnrefLocked(void*, grpc_error*) + 12296344
8  ourgamename                    0x10443bb10 grpc_core::Resolver::ShutdownAndUnrefLocked(void*, grpc_error*) + 9792804
9  ourgamename                    0x103f37eb8 grpc_core::Resolver::ShutdownAndUnrefLocked(void*, grpc_error*) + 4534476
10 ourgamename                    0x103f42f24 grpc_core::Resolver::ShutdownAndUnrefLocked(void*, grpc_error*) + 4579640
11 ourgamename                    0x103f20c54 grpc_core::Resolver::ShutdownAndUnrefLocked(void*, grpc_error*) + 4439656
12 ourgamename                    0x103f29b24 grpc_core::Resolver::ShutdownAndUnrefLocked(void*, grpc_error*) + 4476216
13 ourgamename                    0x102db0c08 RuntimeInvoker_TrueVoid_t22962CB4C05B1D89B55A6E1139F0E87A90987017(void (*)(), MethodInfo const*, void*, void**) + 30234 (Il2CppInvokerTable.cpp:30234)
14 ourgamename                    0x103a58588 il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**) + 550 (Runtime.cpp:550)
15 ourgamename                    0x10346e73c scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool) + 249 (ScriptingApi_Il2Cpp.cpp:249)
16 ourgamename                    0x103477c1c ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool) + 273 (ScriptingInvocation.cpp:273)
17 ourgamename                    0x1034799f4 ScriptingInvocation::InvokeChecked(ScriptingExceptionPtr*) + 69 (ScriptingInvocation.h:69)
18 ourgamename                    0x1034ac784 SerializableManagedRef::CallMethod(Object&, ScriptingMethodPtr) + 60 (ScriptingNativeTypes.h:60)
19 ourgamename                    0x10347f3fc MonoBehaviour::CallAwake() + 1329 (MonoBehaviour.cpp:1329)
20 ourgamename                    0x10347f808 MonoBehaviour::AddToManager() + 1434 (MonoBehaviour.cpp:1434)
21 ourgamename                    0x10347f358 MonoBehaviour::AwakeFromLoad(AwakeFromLoadMode) + 1313 (MonoBehaviour.cpp:1313)
22 ourgamename                    0x1034bc76c AwakeFromLoadQueue::InvokePersistentManagerAwake(AwakeFromLoadQueue::Item*, unsigned int, AwakeFromLoadMode) + 457 (AwakeFromLoadQueue.cpp:457)
23 ourgamename                    0x1034bc61c AwakeFromLoadQueue::PersistentManagerAwakeFromLoad(int, AwakeFromLoadMode) + 290 (AwakeFromLoadQueue.cpp:290)
24 ourgamename                    0x1034bc578 AwakeFromLoadQueue::PersistentManagerAwakeFromLoad() + 157 (AwakeFromLoadQueue.cpp:157)
25 ourgamename                    0x1033cc3c4 LoadSceneOperation::CompleteAwakeSequence() + 805 (LoadSceneOperation.cpp:805)
26 ourgamename                    0x1033cc430 LoadSceneOperation::CompletePreloadManagerLoadScene() + 819 (LoadSceneOperation.cpp:819)
27 ourgamename                    0x1033cc038 LoadSceneOperation::PlayerLoadSceneFromThread() + 645 (LoadSceneOperation.cpp:645)
28 ourgamename                    0x1033cc118 LoadSceneOperation::CompleteLoadFirstScene() + 676 (LoadSceneOperation.cpp:676)
29 ourgamename                    0x1033cbdb4 LoadSceneOperation::IntegrateMainThread() + 375 (LoadSceneOperation.cpp:375)
30 ourgamename                    0x1033ccc04 PreloadManager::UpdatePreloadingSingleStep(PreloadManager::UpdatePreloadingFlags, int) + 402 (PreloadManager.cpp:402)
31 ourgamename                    0x1033cd2e0 PreloadManager::UpdatePreloading() + 535 (PreloadManager.cpp:535)
32 ourgamename                    0x10365985c UnityPlayerLoopImpl(bool) + 298 (LibEntryPoint.mm:298)
33 ourgamename                    0x102d3c8d8 UnityRepaint + 279 (UnityAppController+Rendering.mm:279)
34 ourgamename                    0x102d3c7c4 -[UnityAppController(Rendering) repaintDisplayLink] + 72 (UnityAppController+Rendering.mm:72)
35 QuartzCore                     0x1a3eb1514 CA::smile:isplay::smile:isplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 632
36 IOKit                          0x19e5a4eb0 IODispatchCalloutFromCFMessage + 488
37 CoreFoundation                 0x19d5c16d4 __CFMachPortPerform + 172
38 CoreFoundation                 0x19d5eae5c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56
39 CoreFoundation                 0x19d5ea588 __CFRunLoopDoSource1 + 444
40 CoreFoundation                 0x19d5e545c __CFRunLoopRun + 2168
41 CoreFoundation                 0x19d5e48bc CFRunLoopRunSpecific + 464
42 GraphicsServices               0x1a744f328 GSEventRunModal + 104
43 UIKitCore                      0x1a16796d4 UIApplicationMain + 1936
44 ourgamename                    0x102d35b20 main + 41 (main.mm:41)
45 libdyld.dylib                  0x19d46f460 start + 4
GC Finalizer
0  libsystem_kernel.dylib         0x19d464c8c __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x19d382204 _pthread_cond_wait$VARIANT$mp + 684
2  ourgamename                    0x103a372c0 il2cpp::os::posix::PosixWaitObject::Wait(unsigned int, bool) + 120 (PosixWaitObject.cpp:120)
3  ourgamename                    0x103a10308 il2cpp::gc::FinalizerThread(void*) + 307 (BoehmGC.cpp:307)
4  ourgamename                    0x103a2eb34 il2cpp::os::Thread::RunWrapper(void*) + 176 (Thread.cpp:176)
5  ourgamename                    0x103a30df0 il2cpp::os::ThreadImpl::ThreadStartWrapper(void*) + 106 (ThreadImpl.cpp:106)
6  libsystem_pthread.dylib        0x19d3891ec _pthread_start + 124
7  libsystem_pthread.dylib        0x19d38caec thread_start + 8
IL2CPP Threadpool worker
0  libsystem_kernel.dylib         0x19d46699c kevent + 8
1  libsystem_info.dylib           0x19d514c9c _mdns_search_ex + 1996
2  libsystem_info.dylib           0x19d5143e4 _mdns_search + 128
3  libsystem_info.dylib           0x19d513974 mdns_addrinfo + 896
4  libsystem_info.dylib           0x19d519960 search_addrinfo + 264
5  libsystem_info.dylib           0x19d51dc54 si_addrinfo + 1652
6  libsystem_info.dylib           0x19d511090 _getaddrinfo_internal + 196
7  libsystem_info.dylib           0x19d510fc0 getaddrinfo + 52
8  ourgamename                    0x103a31ad4 il2cpp::os::GetAddressInfo(char const*, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&) + 404 (SocketImpl.cpp:404)
9  ourgamename                    0x103a32214 il2cpp::os::SocketImpl::GetHostByName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&) + 509 (SocketImpl.cpp:509)
10 ourgamename                    0x103a129e0 il2cpp::icalls::System::System::Net::smile:ns::GetHostByName(Il2CppString*, Il2CppString**, Il2CppArray**, Il2CppArray**) + 64 (Dns.cpp:64)
11 ourgamename                    0x104a1cb44 grpc_core::Resolver::ShutdownAndUnrefLocked(void*, grpc_error*) + 15957336
12 ourgamename                    0x104a1c998 grpc_core::Resolver::ShutdownAndUnrefLocked(void*, grpc_error*) + 15956908
13 ourgamename                    0x104a1ccec grpc_core::Resolver::ShutdownAndUnrefLocked(void*, grpc_error*) + 15957760
14 ourgamename                    0x103a58588 il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**) + 550 (Runtime.cpp:550)
15 ourgamename                    0x103a58c20 il2cpp::vm::Runtime::InvokeConvertArgs(MethodInfo const*, void*, Il2CppObject**, int, Il2CppException**) + 651 (Runtime.cpp:651)
16 ourgamename                    0x103a5942c il2cpp::vm::ThreadPoolMs::MessageInvoke(Il2CppObject*, Il2CppMethodMessage*, Il2CppObject**, Il2CppArray**) + 105 (ThreadPoolMs.cpp:105)
17 ourgamename                    0x103a2495c il2cpp::icalls::mscorlib::System::Runtime::Remoting::Messaging::AsyncResult::Invoke(Il2CppObject*) + 44 (AsyncResult.cpp:44)
18 ourgamename                    0x104c96ccc grpc_core::Resolver::ShutdownAndUnrefLocked(void*, grpc_error*) + 18554592
19 ourgamename                    0x102db3cf8 RuntimeInvoker_FalseSByte_t9070AEA2966184235653CB9B4D33B149CDA831DF(void (*)(), MethodInfo const*, void*, void**) + 31423 (Il2CppInvokerTable.cpp:31423)
20 ourgamename                    0x103a2dc28 worker_thread(void*) + 253 (ThreadPoolWorkerThread.cpp:253)
21 ourgamename                    0x103a4fb70 il2cpp::vm::ThreadStart(void*) + 717 (Thread.cpp:717)
22 ourgamename                    0x103a2eb34 il2cpp::os::Thread::RunWrapper(void*) + 176 (Thread.cpp:176)
23 ourgamename                    0x103a30df0 il2cpp::os::ThreadImpl::ThreadStartWrapper(void*) + 106 (ThreadImpl.cpp:106)
24 libsystem_pthread.dylib        0x19d3891ec _pthread_start + 124
25 libsystem_pthread.dylib        0x19d38caec thread_start + 8

I don’t see anything that jumps out at me in these call stack. Initially I thought it might be related to a new managed code thread starting during the shutdown process, but that does not seem to be the case.

We have this crash issue too with the exactly same stack trace. It’s not only iOS. All of our IL2CPP builds including on Android & on Windows have this same crash with the same stack trace. Mono build however doesn’t seem to have this crash issue.

The Unity version we are using is 2019.2.5f1. We used 2019.1.10f1 and 2019.1.14f1 before and all of them have this crash.

Another thing we noticed about this crash is that when we use C# HttpClient with ThreadPool, the crash rate goes a lot higher with most of the crash happening about some mutex lock code.

2 Likes

The crash stack trace:

Thread 45 (crashed)

0   ios                                0x000000010197c7a8 il2cpp::os::FastMutex::Lock()

1   ios                                0x000000010199e774 il2cpp::vm::Thread::SetState(Il2CppThread*, il2cpp::vm::ThreadState)

2   ios                                0x000000010199ee58 il2cpp::vm::ThreadStart(void*)

3   ios                                0x000000010197c234 il2cpp::os::Thread::RunWrapper(void*)

4   ios                                0x000000010197e5e8 il2cpp::os::ThreadImpl::ThreadStartWrapper(void*)

5   libsystem_pthread.dylib            0x0000000215f452c0 _pthread_body

6   libsystem_pthread.dylib            0x0000000215f45220 _pthread_start

7   libsystem_pthread.dylib            0x0000000215f48cdc thread_start
1 Like

Thanks for your reply! Good to know we’re not alone. Are you using gRPC? We’re still looking into this and yeah, it happens also in Android. I’ll come back here if we make any progress.

We are not using gRPC, just plain C# HttpClient. I suspect there is some thread-safety bug in the IL2CPP socket code, but I haven’t found a way to make it consistently crash yet.

We’re revisiting our HttpClient code and our file access code. We believe we might have different threads accessing the same resources at some times. We’ll keep reporting back :slight_smile: