xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.45k stars 511 forks source link

.NET7 iOS App Crashes while it is in Background in production mode, only TestFlight Error shown #18888

Closed SprengerS closed 1 year ago

SprengerS commented 1 year ago

My newly migrated iOS App crashes with a strange crash report in production mode. Only TestFlight shows this crash.

Steps to Reproduce

  1. Build an App and send it to the Apple AppStore
  2. Download this build and test it, send it to the background
  3. After a while in background, the app crashes

Expected Behavior

The app should not crash

Actual Behavior

The app crashes with a strange crash report

Environment

Version information ``` Visual Studio Community 2022 for Mac Version 17.6.2 (build 405) Installation UUID: 6c232f0f-59e6-426a-bef9-f94fc3d28dc9 Runtime .NET 7.0.3 (64-bit) Architecture: Arm64 Microsoft.macOS.Sdk 13.1.1007; git-rev-head:8afca776a0a96613dfb7200e0917bb57f9ed5583; git-branch:release/7.0.1xx-xcode14.2 Roslyn (Language Service) 4.6.0-3.23180.6+99e956e42697a6dd886d1e12478ea2b27cceacfa NuGet Version: 6.4.0.117 .NET SDK (Arm64) SDK: /usr/local/share/dotnet/sdk/7.0.306/Sdks SDK Versions: 7.0.306 7.0.302 7.0.203 7.0.202 7.0.201 7.0.200 7.0.103 7.0.102 6.0.412 6.0.408 6.0.407 6.0.406 6.0.405 MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks .NET SDK (x64) SDK Versions: 7.0.306 7.0.302 7.0.203 7.0.202 7.0.201 7.0.200 7.0.103 7.0.102 6.0.412 6.0.408 6.0.407 6.0.406 6.0.405 3.1.426 .NET Runtime (Arm64) Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 7.0.9 7.0.5 7.0.4 7.0.3 7.0.2 6.0.20 6.0.16 6.0.15 6.0.14 6.0.13 .NET Runtime (x64) Runtime: /usr/local/share/dotnet/x64/dotnet Runtime Versions: 7.0.9 7.0.5 7.0.4 7.0.3 7.0.2 6.0.20 6.0.16 6.0.15 6.0.14 6.0.13 3.1.32 Xamarin.Profiler Version: 1.8.0.49 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler Updater Version: 11 Apple Developer Tools Xcode: 14.3.1 21815 Build: 14E300c Xamarin.Mac Not Installed Xamarin.iOS Version: 16.4.0.6 Visual Studio Community Hash: 97731c92c Branch: xcode14.3 Build date: 2023-04-11 22:38:36-0400 Xamarin.Android Version: 13.2.0.6 (Visual Studio Community) Commit: xamarin-android/d17-5/a200af1 Android SDK: /Users/sprenger_s/Library/Android/sdk Supported Android versions: 12.1 (API level 32) 12.0 (API level 31) 11.0 (API level 30) 10.0 (API level 29) 9.0 (API level 28) 13.0 (API level 33) 7.0 (API level 24) SDK Command-line Tools Version: 7.0 SDK Platform Tools Version: 34.0.4 SDK Build Tools Version: 33.0.2 Build Information: Mono: 6dd9def Java.Interop: xamarin/java.interop/d17-5@149d70fe SQLite: xamarin/sqlite/3.40.1@68c69d8 Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@9f02d77 Microsoft Build of OpenJDK Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk 11.0.16.1 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Eclipse Temurin JDK Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk 1.8.0.302 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Android SDK Manager Version: 17.6.0.50 Hash: a715dca Branch: HEAD Build date: 2023-07-26 17:08:38 UTC Android Device Manager Version: 0.0.0.1309 Hash: 06e3e77 Branch: HEAD Build date: 2023-07-26 17:08:38 UTC Xamarin Designer Version: 17.6.3.9 Hash: 2648399ae8 Branch: remotes/origin/d17-6 Build date: 2023-07-26 17:08:33 UTC Build Information Release ID: 1706020405 Git revision: beaff930b1a0035595265bd63d6ef6d670e93e9e Build date: 2023-07-26 17:06:58+00 Build branch: release-17.6 Build lane: release-17.6 Operating System Mac OS X 13.4.1 Darwin 22.5.0 Darwin Kernel Version 22.5.0 Thu Jun 8 22:22:20 PDT 2023 root:xnu-8796.121.3~7/RELEASE_ARM64_T6000 arm64 ```

Build Logs

Example Project (If Possible)

Crash Report

Incident Identifier: 5FF622DC-2B2F-4056-9612-4588D0B38740 Beta Identifier: 036BC549-7077-42A8-9399-D094CDAB9BD0 Hardware Model: iPhone14,5 Process: Hoermann.BleApp.iOS [507] Path: /private/var/containers/Bundle/Application/FF321FE4-3B8D-42BE-B12D-B74E29A0C6AF/Hoermann.BleApp.iOS.app/Hoermann.BleApp.iOS Identifier: eu.hoermann.ast.bluesecur Version: 23.2.0 (57460) AppStoreTools: 14E221 AppVariant: 1:iPhone14,5:16 Beta: YES Code Type: ARM-64 (Native) Role: unknown Parent Process: launchd [1] Coalition: eu.hoermann.ast.bluesecur [490]

Date/Time: 2023-08-31 12:54:33.1536 +0200 Launch Time: 2023-08-31 12:53:30.5526 +0200 OS Version: iPhone OS 16.6 (20G75) Release Type: User Baseband Version: 2.80.01 Report Version: 104

Exception Type: EXC_CRASH (SIGKILL) Exception Codes: 0x0000000000000000, 0x0000000000000000 Termination Reason: RUNNINGBOARD 3735883980

Triggered by Thread: 0

Thread 0 name: tid_103 Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 libsystem_kernel.dylib 0x1fdb5aca4 mach_msg2_trap + 8 1 libsystem_kernel.dylib 0x1fdb6db74 mach_msg2_internal + 80 2 libsystem_kernel.dylib 0x1fdb6de4c mach_msg_overwrite + 540 3 libsystem_kernel.dylib 0x1fdb5b1e8 mach_msg + 24 4 CoreFoundation 0x1bec14024 CFRunLoopServiceMachPort + 160 5 CoreFoundation 0x1bec15250 CFRunLoopRun + 1208 6 CoreFoundation 0x1bec1a3ec CFRunLoopRunSpecific + 612 7 GraphicsServices 0x1fa13035c GSEventRunModal + 164 8 UIKitCore 0x1c0fa6f58 -[UIApplication _run] + 888 9 UIKitCore 0x1c0fa6bbc UIApplicationMain + 340 10 Hoermann.BleApp.iOS 0x102261240 xamarin_UIApplicationMain + 24 11 Hoermann.BleApp.iOS 0x102590818 do_icall + 3770392 (interp.c:2321) 12 Hoermann.BleApp.iOS 0x10258f538 do_icall_wrapper + 3765560 (interp.c:2362) 13 Hoermann.BleApp.iOS 0x102584f14 interp_exec_method + 3723028 (interp.c:0) 14 Hoermann.BleApp.iOS 0x102582ae8 interp_runtime_invoke + 3713768 (interp.c:2123) 15 Hoermann.BleApp.iOS 0x10254abf4 mono_jit_runtime_invoke + 3484660 (mini-runtime.c:3562) 16 Hoermann.BleApp.iOS 0x10248983c mono_runtime_invoke_checked + 2693180 (object.c:2583) 17 Hoermann.BleApp.iOS 0x10249144c do_exec_main_checked + 2724940 (object.c:0) 18 Hoermann.BleApp.iOS 0x102550d04 mono_jit_exec + 3509508 (driver.c:1310) 19 Hoermann.BleApp.iOS 0x1022755e4 xamarin_main + 513508 (monotouch-main.m:0) 20 Hoermann.BleApp.iOS 0x1026070dc main + 4255964 (main.arm64.mm:81) 21 dyld 0x1de14cdec start + 2220

Thread 1 name: SGen worker Thread 1: 0 libsystem_kernel.dylib 0x1fdb5b578 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x21e9dd078 _pthread_cond_wait + 1232 2 Hoermann.BleApp.iOS 0x10253b194 thread_func + 3420564 (sgen-thread-pool.c:198) 3 libsystem_pthread.dylib 0x21e9d66b8 _pthread_start + 148 4 libsystem_pthread.dylib 0x21e9d5b88 thread_start + 8

Thread 2 name: Finalizer Thread 2: 0 libsystem_kernel.dylib 0x1fdb5ac20 semaphore_wait_trap + 8 1 Hoermann.BleApp.iOS 0x1024c8538 finalizer_thread + 2950456 (gc.c:891) 2 Hoermann.BleApp.iOS 0x1024a3298 start_wrapper_internal + 2798232 (threads.c:0) 3 Hoermann.BleApp.iOS 0x1024a3120 start_wrapper + 2797856 (threads.c:1266) 4 libsystem_pthread.dylib 0x21e9d66b8 _pthread_start + 148 5 libsystem_pthread.dylib 0x21e9d5b88 thread_start + 8

Thread 3 name: com.apple.uikit.eventfetch-thread Thread 3: 0 libsystem_kernel.dylib 0x1fdb5aca4 mach_msg2_trap + 8 1 libsystem_kernel.dylib 0x1fdb6db74 mach_msg2_internal + 80 2 libsystem_kernel.dylib 0x1fdb6de4c mach_msg_overwrite + 540 3 libsystem_kernel.dylib 0x1fdb5b1e8 mach_msg + 24 4 CoreFoundation 0x1bec14024 CFRunLoopServiceMachPort + 160 5 CoreFoundation 0x1bec15250 CFRunLoopRun + 1208 6 CoreFoundation 0x1bec1a3ec CFRunLoopRunSpecific + 612 7 Foundation 0x1b8e96fb4 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212 8 Foundation 0x1b8e96e9c -[NSRunLoop(NSRunLoop) runUntilDate:] + 64 9 UIKitCore 0x1c10d9cc8 -[UIEventFetcher threadMain] + 416 10 Foundation 0x1b8eb0524 NSThreadstart__ + 716 11 libsystem_pthread.dylib 0x21e9d66b8 _pthread_start + 148 12 libsystem_pthread.dylib 0x21e9d5b88 thread_start + 8

Thread 4 name: .NET ThreadPool Worker Thread 4: 0 libsystem_kernel.dylib 0x1fdb5b578 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x21e9dd078 _pthread_cond_wait + 1232 2 Hoermann.BleApp.iOS 0x1024ef4bc mono_os_cond_timedwait + 3110076 (mono-os-mutex.c:75) 3 Hoermann.BleApp.iOS 0x1024f3b4c mono_lifo_semaphore_timed_wait + 3128140 (lifo-semaphore.c:48) 4 Hoermann.BleApp.iOS 0x10259078c do_icall + 3770252 (interp.c:2285) 5 Hoermann.BleApp.iOS 0x10258f570 do_icall_wrapper + 3765616 (interp.c:2368) 6 Hoermann.BleApp.iOS 0x102584f14 interp_exec_method + 3723028 (interp.c:0) 7 Hoermann.BleApp.iOS 0x102582ae8 interp_runtime_invoke + 3713768 (interp.c:2123) 8 Hoermann.BleApp.iOS 0x10254abf4 mono_jit_runtime_invoke + 3484660 (mini-runtime.c:3562) 9 Hoermann.BleApp.iOS 0x10248983c mono_runtime_invoke_checked + 2693180 (object.c:2583) 10 Hoermann.BleApp.iOS 0x1024a3390 start_wrapper_internal + 2798480 (threads.c:1215) 11 Hoermann.BleApp.iOS 0x1024a3120 start_wrapper + 2797856 (threads.c:1266) 12 libsystem_pthread.dylib 0x21e9d66b8 _pthread_start + 148 13 libsystem_pthread.dylib 0x21e9d5b88 thread_start + 8

Thread 5 name: .NET ThreadPool Gate Thread 5: 0 libsystem_kernel.dylib 0x1fdb5b578 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x21e9dd0a4 _pthread_cond_wait + 1276 2 Hoermann.BleApp.iOS 0x1022c6b7c SystemNative_LowLevelMonitor_TimedWait + 104 3 Hoermann.BleApp.iOS 0x10259078c do_icall + 3770252 (interp.c:2285) 4 Hoermann.BleApp.iOS 0x10258f538 do_icall_wrapper + 3765560 (interp.c:2362) 5 Hoermann.BleApp.iOS 0x102584f14 interp_exec_method + 3723028 (interp.c:0) 6 Hoermann.BleApp.iOS 0x102582ae8 interp_runtime_invoke + 3713768 (interp.c:2123) 7 Hoermann.BleApp.iOS 0x10254abf4 mono_jit_runtime_invoke + 3484660 (mini-runtime.c:3562) 8 Hoermann.BleApp.iOS 0x10248983c mono_runtime_invoke_checked + 2693180 (object.c:2583) 9 Hoermann.BleApp.iOS 0x1024a3390 start_wrapper_internal + 2798480 (threads.c:1215) 10 Hoermann.BleApp.iOS 0x1024a3120 start_wrapper + 2797856 (threads.c:1266) 11 libsystem_pthread.dylib 0x21e9d66b8 _pthread_start + 148 12 libsystem_pthread.dylib 0x21e9d5b88 thread_start + 8

Thread 6 name: .NET ThreadPool Worker Thread 6: 0 libsystem_kernel.dylib 0x1fdb5b578 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x21e9dd078 _pthread_cond_wait + 1232 2 Hoermann.BleApp.iOS 0x1024ef4bc mono_os_cond_timedwait + 3110076 (mono-os-mutex.c:75) 3 Hoermann.BleApp.iOS 0x1024f3b4c mono_lifo_semaphore_timed_wait + 3128140 (lifo-semaphore.c:48) 4 Hoermann.BleApp.iOS 0x10259078c do_icall + 3770252 (interp.c:2285) 5 Hoermann.BleApp.iOS 0x10258f570 do_icall_wrapper + 3765616 (interp.c:2368) 6 Hoermann.BleApp.iOS 0x102584f14 interp_exec_method + 3723028 (interp.c:0) 7 Hoermann.BleApp.iOS 0x102582ae8 interp_runtime_invoke + 3713768 (interp.c:2123) 8 Hoermann.BleApp.iOS 0x10254abf4 mono_jit_runtime_invoke + 3484660 (mini-runtime.c:3562) 9 Hoermann.BleApp.iOS 0x10248983c mono_runtime_invoke_checked + 2693180 (object.c:2583) 10 Hoermann.BleApp.iOS 0x1024a3390 start_wrapper_internal + 2798480 (threads.c:1215) 11 Hoermann.BleApp.iOS 0x1024a3120 start_wrapper + 2797856 (threads.c:1266) 12 libsystem_pthread.dylib 0x21e9d66b8 _pthread_start + 148 13 libsystem_pthread.dylib 0x21e9d5b88 thread_start + 8

Thread 7 name: .NET Timer Thread 7: 0 libsystem_kernel.dylib 0x1fdb5b578 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x21e9dd0a4 _pthread_cond_wait + 1276 2 Hoermann.BleApp.iOS 0x1022c6b7c SystemNative_LowLevelMonitor_TimedWait + 104 3 Hoermann.BleApp.iOS 0x10259078c do_icall + 3770252 (interp.c:2285) 4 Hoermann.BleApp.iOS 0x10258f538 do_icall_wrapper + 3765560 (interp.c:2362) 5 Hoermann.BleApp.iOS 0x102584f14 interp_exec_method + 3723028 (interp.c:0) 6 Hoermann.BleApp.iOS 0x102582ae8 interp_runtime_invoke + 3713768 (interp.c:2123) 7 Hoermann.BleApp.iOS 0x10254abf4 mono_jit_runtime_invoke + 3484660 (mini-runtime.c:3562) 8 Hoermann.BleApp.iOS 0x10248983c mono_runtime_invoke_checked + 2693180 (object.c:2583) 9 Hoermann.BleApp.iOS 0x1024a3390 start_wrapper_internal + 2798480 (threads.c:1215) 10 Hoermann.BleApp.iOS 0x1024a3120 start_wrapper + 2797856 (threads.c:1266) 11 libsystem_pthread.dylib 0x21e9d66b8 _pthread_start + 148 12 libsystem_pthread.dylib 0x21e9d5b88 thread_start + 8

Thread 8 name: tid_420f Thread 8: 0 libsystem_pthread.dylib 0x21e9d5b74 start_wqthread + 0

Thread 9 name: com.apple.NSURLConnectionLoader Thread 9: 0 libsystem_kernel.dylib 0x1fdb5aca4 mach_msg2_trap + 8 1 libsystem_kernel.dylib 0x1fdb6db74 mach_msg2_internal + 80 2 libsystem_kernel.dylib 0x1fdb6de4c mach_msg_overwrite + 540 3 libsystem_kernel.dylib 0x1fdb5b1e8 mach_msg + 24 4 CoreFoundation 0x1bec14024 CFRunLoopServiceMachPort + 160 5 CoreFoundation 0x1bec15250 CFRunLoopRun + 1208 6 CoreFoundation 0x1bec1a3ec CFRunLoopRunSpecific + 612 7 CFNetwork 0x1bfe056f0 0x1bfbad000 + 2459376 8 Foundation 0x1b8eb0524 NSThreadstart__ + 716 9 libsystem_pthread.dylib 0x21e9d66b8 _pthread_start + 148 10 libsystem_pthread.dylib 0x21e9d5b88 thread_start + 8

Thread 10 name: .NET ThreadPool Worker Thread 10: 0 libsystem_kernel.dylib 0x1fdb5b578 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x21e9dd078 _pthread_cond_wait + 1232 2 Hoermann.BleApp.iOS 0x1024ef4bc mono_os_cond_timedwait + 3110076 (mono-os-mutex.c:75) 3 Hoermann.BleApp.iOS 0x1024f3b4c mono_lifo_semaphore_timed_wait + 3128140 (lifo-semaphore.c:48) 4 Hoermann.BleApp.iOS 0x10259078c do_icall + 3770252 (interp.c:2285) 5 Hoermann.BleApp.iOS 0x10258f570 do_icall_wrapper + 3765616 (interp.c:2368) 6 Hoermann.BleApp.iOS 0x102584f14 interp_exec_method + 3723028 (interp.c:0) 7 Hoermann.BleApp.iOS 0x102582ae8 interp_runtime_invoke + 3713768 (interp.c:2123) 8 Hoermann.BleApp.iOS 0x10254abf4 mono_jit_runtime_invoke + 3484660 (mini-runtime.c:3562) 9 Hoermann.BleApp.iOS 0x10248983c mono_runtime_invoke_checked + 2693180 (object.c:2583) 10 Hoermann.BleApp.iOS 0x1024a3390 start_wrapper_internal + 2798480 (threads.c:1215) 11 Hoermann.BleApp.iOS 0x1024a3120 start_wrapper + 2797856 (threads.c:1266) 12 libsystem_pthread.dylib 0x21e9d66b8 _pthread_start + 148 13 libsystem_pthread.dylib 0x21e9d5b88 thread_start + 8

Thread 11 name: .NET ThreadPool Worker Thread 11: 0 libsystem_kernel.dylib 0x1fdb5b578 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x21e9dd078 _pthread_cond_wait + 1232 2 Hoermann.BleApp.iOS 0x1024ef4bc mono_os_cond_timedwait + 3110076 (mono-os-mutex.c:75) 3 Hoermann.BleApp.iOS 0x1024f3b4c mono_lifo_semaphore_timed_wait + 3128140 (lifo-semaphore.c:48) 4 Hoermann.BleApp.iOS 0x10259078c do_icall + 3770252 (interp.c:2285) 5 Hoermann.BleApp.iOS 0x10258f570 do_icall_wrapper + 3765616 (interp.c:2368) 6 Hoermann.BleApp.iOS 0x102584f14 interp_exec_method + 3723028 (interp.c:0) 7 Hoermann.BleApp.iOS 0x102582ae8 interp_runtime_invoke + 3713768 (interp.c:2123) 8 Hoermann.BleApp.iOS 0x10254abf4 mono_jit_runtime_invoke + 3484660 (mini-runtime.c:3562) 9 Hoermann.BleApp.iOS 0x10248983c mono_runtime_invoke_checked + 2693180 (object.c:2583) 10 Hoermann.BleApp.iOS 0x1024a3390 start_wrapper_internal + 2798480 (threads.c:1215) 11 Hoermann.BleApp.iOS 0x1024a3120 start_wrapper + 2797856 (threads.c:1266) 12 libsystem_pthread.dylib 0x21e9d66b8 _pthread_start + 148 13 libsystem_pthread.dylib 0x21e9d5b88 thread_start + 8

Thread 12 name: .NET ThreadPool Worker Thread 12: 0 libsystem_kernel.dylib 0x1fdb5b578 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x21e9dd078 _pthread_cond_wait + 1232 2 Hoermann.BleApp.iOS 0x1024ef4bc mono_os_cond_timedwait + 3110076 (mono-os-mutex.c:75) 3 Hoermann.BleApp.iOS 0x1024f3b4c mono_lifo_semaphore_timed_wait + 3128140 (lifo-semaphore.c:48) 4 Hoermann.BleApp.iOS 0x10259078c do_icall + 3770252 (interp.c:2285) 5 Hoermann.BleApp.iOS 0x10258f570 do_icall_wrapper + 3765616 (interp.c:2368) 6 Hoermann.BleApp.iOS 0x102584f14 interp_exec_method + 3723028 (interp.c:0) 7 Hoermann.BleApp.iOS 0x102582ae8 interp_runtime_invoke + 3713768 (interp.c:2123) 8 Hoermann.BleApp.iOS 0x10254abf4 mono_jit_runtime_invoke + 3484660 (mini-runtime.c:3562) 9 Hoermann.BleApp.iOS 0x10248983c mono_runtime_invoke_checked + 2693180 (object.c:2583) 10 Hoermann.BleApp.iOS 0x1024a3390 start_wrapper_internal + 2798480 (threads.c:1215) 11 Hoermann.BleApp.iOS 0x1024a3120 start_wrapper + 2797856 (threads.c:1266) 12 libsystem_pthread.dylib 0x21e9d66b8 _pthread_start + 148 13 libsystem_pthread.dylib 0x21e9d5b88 thread_start + 8

Thread 13 name: JavaScriptCore libpas scavenger Thread 13: 0 libsystem_kernel.dylib 0x1fdb5b578 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x21e9dd078 _pthread_cond_wait + 1232 2 JavaScriptCore 0x1d23f7d84 scavenger_thread_main + 1620 3 libsystem_pthread.dylib 0x21e9d66b8 _pthread_start + 148 4 libsystem_pthread.dylib 0x21e9d5b88 thread_start + 8

Thread 14: 0 libsystem_pthread.dylib 0x21e9d5b74 start_wqthread + 0

Thread 0 crashed with ARM Thread State (64-bit): x0: 0x0000000010004005 x1: 0x0000000507000806 x2: 0x0000000200000000 x3: 0x00000b0300000000 x4: 0x0000000000000000 x5: 0x00000b0300000000 x6: 0x0000000000000002 x7: 0x00000000ffffffff x8: 0xfffffffffffffbbf x9: 0x0000000000000000 x10: 0x0000000000000b03 x11: 0x0000000000000000 x12: 0x00000000016e3600 x13: 0x0000000000000b03 x14: 0x0000520000000000 x15: 0x0000000000000000 x16: 0xffffffffffffffd1 x17: 0x0000520000005202 x18: 0x0000000000000000 x19: 0x00000000ffffffff x20: 0x0000000000000002 x21: 0x00000b0300000000 x22: 0x0000000000000000 x23: 0x00000b0300000000 x24: 0x000000016dc05a68 x25: 0x0000000200000000 x26: 0x0000000507000806 x27: 0x0000000507000806 x28: 0x0000000215542000 fp: 0x000000016dc059d0 lr: 0x00000001fdb6db74 sp: 0x000000016dc05980 pc: 0x00000001fdb5aca4 cpsr: 0x40001000 far: 0x00000001055b0000 esr: 0x56000080 Address size fault

Binary Images: 0x1021f8000 - 0x1027d7fff Hoermann.BleApp.iOS arm64 /private/var/containers/Bundle/Application/FF321FE4-3B8D-42BE-B12D-B74E29A0C6AF/Hoermann.BleApp.iOS.app/Hoermann.BleApp.iOS 0x1029b4000 - 0x1029d7fff IQKeyboardManager arm64 <128fdcb57abd3ebbb92f3f953025ddd3> /private/var/containers/Bundle/Application/FF321FE4-3B8D-42BE-B12D-B74E29A0C6AF/Hoermann.BleApp.iOS.app/Frameworks/IQKeyboardManager.framework/IQKeyboardManager 0x102988000 - 0x10298ffff WidgetCenterProxy arm64 <2cd7d4b467ad36da85c9085557d11f30> /private/var/containers/Bundle/Application/FF321FE4-3B8D-42BE-B12D-B74E29A0C6AF/Hoermann.BleApp.iOS.app/Frameworks/WidgetCenterProxy.framework/WidgetCenterProxy 0x10969c000 - 0x1096a7fff libobjc-trampolines.dylib arm64e <7e77fc541c3331c086e81fb7bf12836c> /private/preboot/Cryptexes/OS/usr/lib/libobjc-trampolines.dylib 0x1fdb5a000 - 0x1fdb91fe7 libsystem_kernel.dylib arm64e <681b06a07f6b3fa3a2ce063dc1da7b1b> /usr/lib/system/libsystem_kernel.dylib 0x1beb9b000 - 0x1bef82fff CoreFoundation arm64e /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 0x1fa12f000 - 0x1fa137fff GraphicsServices arm64e /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices 0x1c0c0a000 - 0x1c242efff UIKitCore arm64e <7d57a1d1856f338d97db880c4ec8b02e> /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore 0x1de137000 - 0x1de1bca53 dyld arm64e /usr/lib/dyld 0x21e9d5000 - 0x21e9e0ff3 libsystem_pthread.dylib arm64e /usr/lib/system/libsystem_pthread.dylib 0x1b8e55000 - 0x1b9732fff Foundation arm64e <1715de5d08933af0b0c0550bb14f91ec> /System/Library/Frameworks/Foundation.framework/Foundation 0x1bfbad000 - 0x1bff77fff CFNetwork arm64e <045d4271e64e3229a49fcaff707aa77f> /System/Library/Frameworks/CFNetwork.framework/CFNetwork 0x1d22e4000 - 0x1d39fcfff JavaScriptCore arm64e <9840b0ef5a923bcf97fcf8f58aa14d39> /System/Library/Frameworks/JavaScriptCore.framework/JavaScriptCore

Perhaps you can help me to interpret this crash

rolfbjarne commented 1 year ago

This is the important part of this crash report:

Exception Type: EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Termination Reason: RUNNINGBOARD 3735883980

Apple's documentation says: https://developer.apple.com/documentation/xcode/understanding-the-exception-types-in-a-crash-report#EXCCRASH-SIGKILL

The code is 3735883980 = 0xDEAD10CC:

"0xdead10cc (pronounced β€œdead lock”). The operating system terminated the app because it held on to a file lock or SQLite database lock during suspension. Request additional background execution time on the main thread with beginBackgroundTask(withName:expirationHandler:). Make this request well before starting to write to the file in order to complete those operations and relinquish the lock before the app suspends. In an app extension, use beginActivity(options:reason:) to manage this work."

cho-trackman commented 10 months ago

@SprengerS did you find the issue? I have an identical stack trace when sharing a file with UIActivityViewController.

SprengerS commented 10 months ago

For me it seems to solve the with the [beginBackgroundTask(withName:expirationHandler:)](https://developer.apple.com/documentation/uikit/uiapplication/1623051-beginbackgroundtask). This worked for the first sign, but it was not the Problem solver. I receive a lot of crashes in Xcode with the crash signature above and I don't know why. All crashes seems to be in the background of the app. We use SQLite and LiteDb Databases in our app. For every Database I have added the Background Task to close the DB Connection when the app enter the background state.

Does this error occur when saving, creating or reading files? This is a new information for me.

cho-trackman commented 10 months ago

I actually just (after 2,5 days) narrowed the issue down to a specific file held open when entering the background. I used the code here to get all open file descriptors: https://developer.apple.com/forums/thread/655225?answerId=623114022#623114022

SprengerS commented 10 months ago

How did you get the open file descriptors in .NET? In you post I only found Swift/C++ Code which can only be executed via a Xamarin Binding Library

cho-trackman commented 10 months ago

Yeah, we have a binding lib with SwiftUI. I updated the code to look like this:

@objc(FileHelper)
public class FileHelper : NSObject {
    @objc public static func openFilePaths(_: NSString? = nil) -> [NSString] {
        (0..<getdtablesize()).map { fd in
            // Return "" for invalid file descriptors.
            var flags: CInt = 0
            guard fcntl(fd, F_GETFL, &flags) >= 0 else {
                return NSString("")
            }
            // Return "?" for file descriptors not associated with a path, for
            // example, a socket.
            var path = [CChar](repeating: 0, count: Int(MAXPATHLEN))
            guard fcntl(fd, F_GETPATH, &path) >= 0 else {
                return NSString("?")
            }
            return NSString(cString: path, encoding: NSUTF8StringEncoding)!
        }
    }
}

The weird _: NSString? = nil part is to force sharpie to make it a method and not just a prop, that breaks the build.

rolfbjarne commented 10 months ago

Here's a C# version of the Swift/C code: https://gist.github.com/rolfbjarne/2ac09145d4e969ff4c679ec8c109ebe6

SprengerS commented 10 months ago

@rolfbjarne: Thank you very much. But it is really strange that this deadlock crash now occurs. Only our two sqlite Databases are detected.

fd 0: /dev/null
fd 1: /dev/null
fd 2: /dev/null
fd 3: /dev/urandom
fd 5: /private/var/mobile/Containers/Shared/AppGroup/0CE26CCE-BBF2-4AC4-8F46-CC47002D2A13/app.sqlite3
fd 6: /private/var/mobile/Containers/Data/Application/4328E0BC-ECE5-4E3B-87AB-0B7DC4395222/Library/Logs/all.log
fd 7: /private/var/mobile/Containers/Data/Application/4328E0BC-ECE5-4E3B-87AB-0B7DC4395222/Library/Application Support/Google/FirebaseMessaging/rmq2.sqlite
fd 9: /private/var/mobile/Containers/Shared/AppGroup/0CE26CCE-BBF2-4AC4-8F46-CC47002D2A13/hoermann-ble.sqlite3
fd 14: /private/var/mobile/Containers/Data/Application/4328E0BC-ECE5-4E3B-87AB-0B7DC4395222/Library/Caches/eu.hoermann.ast.bluesecur/Cache.db
fd 15: /private/var/mobile/Containers/Data/Application/4328E0BC-ECE5-4E3B-87AB-0B7DC4395222/Library/Caches/eu.hoermann.ast.bluesecur/Cache.db-wal
fd 16: /private/var/mobile/Containers/Data/Application/4328E0BC-ECE5-4E3B-87AB-0B7DC4395222/Library/Caches/eu.hoermann.ast.bluesecur/Cache.db-shm
fd 17: /private/var/mobile/Containers/Data/Application/4328E0BC-ECE5-4E3B-87AB-0B7DC4395222/Library/HTTPStorages/eu.hoermann.ast.bluesecur/httpstorages.sqlite
fd 18: /private/var/mobile/Containers/Data/Application/4328E0BC-ECE5-4E3B-87AB-0B7DC4395222/Library/HTTPStorages/eu.hoermann.ast.bluesecur/httpstorages.sqlite-wal
fd 19: /private/var/mobile/Containers/Data/Application/4328E0BC-ECE5-4E3B-87AB-0B7DC4395222/Library/HTTPStorages/eu.hoermann.ast.bluesecur/httpstorages.sqlite-shm
fd 21: /private/var/mobile/Containers/Data/Application/4328E0BC-ECE5-4E3B-87AB-0B7DC4395222/Library/Caches/eu.hoermann.ast.bluesecur/Cache.db
fd 22: /private/var/mobile/Containers/Data/Application/4328E0BC-ECE5-4E3B-87AB-0B7DC4395222/Library/Caches/eu.hoermann.ast.bluesecur/Cache.db-wal

We have never closed this two databases when the app was entering the background mode. This was not necessary with Xamarin, but now with .NET 7 it seems to be necessary.

cho-trackman commented 10 months ago

I found the issue on our side. It was the leaveOpen option on the ZipArchive constructor causing it. I saw a zip file added to list of file descriptors when printing in DidEnterBackground (only randomly).

rolfbjarne commented 10 months ago

This was not necessary with Xamarin, but now with .NET 7 it seems to be necessary.

One theory is that in Xamarin you were unintentionally relying on the GC cleaning stuff up and closing these files, and the GC behavior subtly changed in .NET (note that the GC is by design unpredictable, so nobody should rely on specific GC behavior).

In any case, closing these files when the app is backgrounded is the right thing to do.

cho-trackman commented 10 months ago

Did you try to disable logging to file?

cho-trackman commented 10 months ago

@rolfbjarne should the GC also cleanup open files in this case:

using var archive = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen: true);
rolfbjarne commented 10 months ago

@rolfbjarne should the GC also cleanup open files in this case:

using var archive = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen: true);

If it can collect stream at some point, then yes.

SprengerS commented 10 months ago

Did you try to disable logging to file?

If I understand Apple technical documentation this deadlock crash occurs only in the App Group Container. In some cases we are creating a Zip Archive in the App Group Container in order to send this archive to the Apple Watch. For this we are using System.IO.Compression.ZipFile.CreateFromDirectory(exportPath, exportZipFile);. Could this also be a problem? In this System Implementation I assume that the ZipFile is closed automatically when leaving CreateFromDirectory method.

cho-trackman commented 10 months ago

@SprengerS If you have a device with the crash happening recently you can try to grab the system logs with e.g. sudo log collect --device-udid "0000xxx-xxxxxx" --last 4d -output logs. Filter on Found locked file lock: Screenshot 2023-11-21 at 14 25 52

In this case the app is crashing because of this line of code:

var json = new StreamReader(fullPath).ReadToEnd();

It's indeed not the best code and rely on the GC to eventually close the open file.

We didn't see crashes like this before updating to net7 and I assume it's because the GC runs less aggressively than it did under Xamarin, can you confirm @rolfbjarne?

rolfbjarne commented 10 months ago

We didn't see crashes like this before updating to net7 and I assume it's because the GC runs less aggressively than it did under Xamarin, can you confirm @rolfbjarne?

AFAIK we didn't do anything on purpose to make the GC run less aggressively, but the GC is by nature impredictable, so I would be surprised if you didn't find different behaviour between versions.