Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS][MacCatalyst] error: mono_coop_cond_broadcast Cannot transition thread from STATE_BLOCKING with DO_BLOCKING #88405

Closed
simonrozsival opened this issue Jul 5, 2023 · 10 comments · Fixed by #88436
Assignees
Labels
area-VM-threading-mono os-maccatalyst MacCatalyst OS runtime-mono specific to the Mono runtime
Milestone

Comments

@simonrozsival
Copy link
Member

While working on xamarin/xamarin-macios, I experienced a crash in mono with the following stack trace when building an app in the Debug configuration:

./xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView
2023-06-30 16:38:37.601 MySingleView[62121:11410156] error: mono_coop_cond_broadcast Cannot transition thread 0x1e7cf5e00 from STATE_BLOCKING with DO_BLOCKING

=================================================================
        Native Crash Reporting
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
        Native stacktrace:
=================================================================
        0x10e8be65c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_dump_native_crash_info
        0x10e87d578 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_handle_native_crash
        0x10ea9c1a0 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : sigabrt_signal_handler.cold.1
        0x10e8bdf10 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_runtime_setup_stat_profiler
        0x18cd26a24 - /usr/lib/system/libsystem_platform.dylib : _sigtramp
        0x18ccf7c28 - /usr/lib/system/libsystem_pthread.dylib : pthread_kill
        0x18cc05ae8 - /usr/lib/system/libsystem_c.dylib : abort
        0x10e13418c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libxamarin-dotnet-debug.dylib : _ZL12log_callbackPKcS0_S0_iPv
        0x10e8fa3d4 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : monoeg_g_logv
        0x10e8fa508 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : monoeg_g_log
        0x10e794548 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_threads_transition_do_blocking
        0x10e795ab8 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_threads_enter_gc_safe_region_unbalanced_with_info
        0x10e7238ac - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_runtime_class_init_full
        0x10e6f1efc - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor_raw
        0x103bcb4f8 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : wrapper_managed_to_native_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor_intptr
        0x103bcaaf4 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor_System_RuntimeTypeHandle
        0x1038feb60 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : System_SR_InternalGetResourceString_string
        0x1038fee9c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : System_SR_GetResourceString_string
        0x103901b00 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : System_SR_get_Arg_NullReferenceException
        0x1038b390c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : System_NullReferenceException__ctor
        0x1040ea398 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr
        0x10e7ec970 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_jit_runtime_invoke
        0x10e72313c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_runtime_invoke_checked
        0x10e722fec - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_runtime_object_init_handle
        0x10e6dc7c4 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_exception_new_by_name
        0x10e6dc6a8 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_exception_from_name_domain
        0x10e87b784 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_handle_exception_internal
        0x10e87b6e8 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_handle_exception
        0x10e8bae2c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : handle_signal_exception
        0x105cb53fc - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : -[MySingleView_AppDelegate init]
        0x105cb53fc - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : -[MySingleView_AppDelegate init]
        0x1b8717514 - /System/iOSSupport/System/Library/PrivateFrameworks/UIKitCore.framework/Versions/A/UIKitCore : _UIApplicationMainPreparations
        0x1b8547094 - /System/iOSSupport/System/Library/PrivateFrameworks/UIKitCore.framework/Versions/A/UIKitCore : UIApplicationMain
        0x10e104e1c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libxamarin-dotnet-debug.dylib : xamarin_UIApplicationMain
        0x105901420 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : wrapper_managed_to_native_UIKit_UIApplication_xamarin_UIApplicationMain_int_intptr_intptr_intptr_intptr_
        0x104fd10d4 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr
        0x104fd13bc - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : UIKit_UIApplication_Main_string___System_Type_System_Type
        0x100731938 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : MySingleView_Application_Main_string__
        0x1040ea398 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr
        0x10e7ec970 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_jit_runtime_invoke
        0x10e72313c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_runtime_invoke_checked
        0x10e72addc - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : do_exec_main_checked
        0x10e83fa24 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_jit_exec
        0x10e14829c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libxamarin-dotnet-debug.dylib : xamarin_main
        0x105cb5088 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : main
        0x18c99ff28 - /usr/lib/dyld : start

=================================================================
        Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x18ccc0724):0x18ccc0714  ff 0f 5f d6 c0 03 5f d6 10 29 80 d2 01 10 00 d4  .._..._..)......
0x18ccc0724  03 01 00 54 7f 23 03 d5 fd 7b bf a9 fd 03 00 91  ...T.#...{......
0x18ccc0734  65 e0 ff 97 bf 03 00 91 fd 7b c1 a8 ff 0f 5f d6  e........{...._.
0x18ccc0744  c0 03 5f d6 70 0a 80 d2 01 10 00 d4 03 01 00 54  .._.p..........T

=================================================================
        Managed Stacktrace:
=================================================================
          at <unknown> <0xffffffff>
          at System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor <0x00007>
          at System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor <0x00033>
          at System.SR:InternalGetResourceString <0x0075f>
          at System.SR:GetResourceString <0x0006b>
          at System.SR:get_Arg_NullReferenceException <0x0002f>
          at System.NullReferenceException:.ctor <0x0002b>
          at System.Object:runtime_invoke_dynamic <0x00127>
          at <unknown> <0xffffffff>
          at UIKit.UIApplication:xamarin_UIApplicationMain <0x00007>
          at UIKit.UIApplication:UIApplicationMain <0x00063>
          at UIKit.UIApplication:Main <0x0013b>
          at MySingleView.Application:Main <0x00097>
          at System.Object:runtime_invoke_dynamic <0x00127>
=================================================================
make: *** [run-test] Abort trap: 6

The same code works fine with /p:MtouchDebug=false or in the Release configuration.

I'm not sure if this is a bug in Mono or in Xamarin. It seems to be similar to #47121 and xamarin/xamarin-macios#7742.

/cc @akoeplinger @ivanpovazan @rolfbjarne

@simonrozsival simonrozsival added runtime-mono specific to the Mono runtime os-maccatalyst MacCatalyst OS labels Jul 5, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jul 5, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jul 5, 2023
@ghost
Copy link

ghost commented Jul 5, 2023

Tagging subscribers to 'os-maccatalyst': @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

Issue Details

While working on xamarin/xamarin-macios, I experienced a crash in mono with the following stack trace when building an app in the Debug configuration:

./xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView
2023-06-30 16:38:37.601 MySingleView[62121:11410156] error: mono_coop_cond_broadcast Cannot transition thread 0x1e7cf5e00 from STATE_BLOCKING with DO_BLOCKING

=================================================================
        Native Crash Reporting
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
        Native stacktrace:
=================================================================
        0x10e8be65c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_dump_native_crash_info
        0x10e87d578 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_handle_native_crash
        0x10ea9c1a0 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : sigabrt_signal_handler.cold.1
        0x10e8bdf10 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_runtime_setup_stat_profiler
        0x18cd26a24 - /usr/lib/system/libsystem_platform.dylib : _sigtramp
        0x18ccf7c28 - /usr/lib/system/libsystem_pthread.dylib : pthread_kill
        0x18cc05ae8 - /usr/lib/system/libsystem_c.dylib : abort
        0x10e13418c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libxamarin-dotnet-debug.dylib : _ZL12log_callbackPKcS0_S0_iPv
        0x10e8fa3d4 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : monoeg_g_logv
        0x10e8fa508 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : monoeg_g_log
        0x10e794548 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_threads_transition_do_blocking
        0x10e795ab8 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_threads_enter_gc_safe_region_unbalanced_with_info
        0x10e7238ac - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_runtime_class_init_full
        0x10e6f1efc - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor_raw
        0x103bcb4f8 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : wrapper_managed_to_native_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor_intptr
        0x103bcaaf4 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor_System_RuntimeTypeHandle
        0x1038feb60 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : System_SR_InternalGetResourceString_string
        0x1038fee9c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : System_SR_GetResourceString_string
        0x103901b00 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : System_SR_get_Arg_NullReferenceException
        0x1038b390c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : System_NullReferenceException__ctor
        0x1040ea398 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr
        0x10e7ec970 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_jit_runtime_invoke
        0x10e72313c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_runtime_invoke_checked
        0x10e722fec - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_runtime_object_init_handle
        0x10e6dc7c4 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_exception_new_by_name
        0x10e6dc6a8 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_exception_from_name_domain
        0x10e87b784 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_handle_exception_internal
        0x10e87b6e8 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_handle_exception
        0x10e8bae2c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : handle_signal_exception
        0x105cb53fc - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : -[MySingleView_AppDelegate init]
        0x105cb53fc - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : -[MySingleView_AppDelegate init]
        0x1b8717514 - /System/iOSSupport/System/Library/PrivateFrameworks/UIKitCore.framework/Versions/A/UIKitCore : _UIApplicationMainPreparations
        0x1b8547094 - /System/iOSSupport/System/Library/PrivateFrameworks/UIKitCore.framework/Versions/A/UIKitCore : UIApplicationMain
        0x10e104e1c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libxamarin-dotnet-debug.dylib : xamarin_UIApplicationMain
        0x105901420 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : wrapper_managed_to_native_UIKit_UIApplication_xamarin_UIApplicationMain_int_intptr_intptr_intptr_intptr_
        0x104fd10d4 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr
        0x104fd13bc - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : UIKit_UIApplication_Main_string___System_Type_System_Type
        0x100731938 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : MySingleView_Application_Main_string__
        0x1040ea398 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr
        0x10e7ec970 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_jit_runtime_invoke
        0x10e72313c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_runtime_invoke_checked
        0x10e72addc - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : do_exec_main_checked
        0x10e83fa24 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libmonosgen-2.0.dylib : mono_jit_exec
        0x10e14829c - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MonoBundle/libxamarin-dotnet-debug.dylib : xamarin_main
        0x105cb5088 - ./xamarin/xamarin-macios/tests/dotnet/MySingleView/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/MySingleView.app/Contents/MacOS/MySingleView : main
        0x18c99ff28 - /usr/lib/dyld : start

=================================================================
        Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x18ccc0724):0x18ccc0714  ff 0f 5f d6 c0 03 5f d6 10 29 80 d2 01 10 00 d4  .._..._..)......
0x18ccc0724  03 01 00 54 7f 23 03 d5 fd 7b bf a9 fd 03 00 91  ...T.#...{......
0x18ccc0734  65 e0 ff 97 bf 03 00 91 fd 7b c1 a8 ff 0f 5f d6  e........{...._.
0x18ccc0744  c0 03 5f d6 70 0a 80 d2 01 10 00 d4 03 01 00 54  .._.p..........T

=================================================================
        Managed Stacktrace:
=================================================================
          at <unknown> <0xffffffff>
          at System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor <0x00007>
          at System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor <0x00033>
          at System.SR:InternalGetResourceString <0x0075f>
          at System.SR:GetResourceString <0x0006b>
          at System.SR:get_Arg_NullReferenceException <0x0002f>
          at System.NullReferenceException:.ctor <0x0002b>
          at System.Object:runtime_invoke_dynamic <0x00127>
          at <unknown> <0xffffffff>
          at UIKit.UIApplication:xamarin_UIApplicationMain <0x00007>
          at UIKit.UIApplication:UIApplicationMain <0x00063>
          at UIKit.UIApplication:Main <0x0013b>
          at MySingleView.Application:Main <0x00097>
          at System.Object:runtime_invoke_dynamic <0x00127>
=================================================================
make: *** [run-test] Abort trap: 6

The same code works fine with /p:MtouchDebug=false or in the Release configuration.

I'm not sure if this is a bug in Mono or in Xamarin. It seems to be similar to #47121 and xamarin/xamarin-macios#7742.

/cc @akoeplinger @ivanpovazan @rolfbjarne

Author: simonrozsival
Assignees: -
Labels:

runtime-mono, os-maccatalyst

Milestone: -

@akoeplinger akoeplinger added area-Diagnostics-mono and removed untriaged New issue has not been triaged by the area owner needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jul 5, 2023
@akoeplinger akoeplinger added this to the 8.0.0 milestone Jul 5, 2023
@akoeplinger
Copy link
Member

mono_runtime_setup_stat_profiler in the stack is different from the mentioned issues so might provide a good hint, I assume we only enable this in debug mode.

/cc @lambdageek

@lambdageek
Copy link
Member

I think mono_runtime_setup_stat_profiler isn't related. There's a call to mono_threads_transition_do_blocking and then a call to monoeg_g_log which is usually the start of failed assertion.

It looks like we ended up in GC Safe somehow at mono_coop_cond_broadcast (&lock->cond); in mono_runtime_class_init_full. That's not really supposed to happen

@lambdageek
Copy link
Member

@simonrozsival Does this happen with net8.0-maccatalyst, too or only net7.0-maccatalyst

@lambdageek
Copy link
Member

Hmm... I think the real issue is in -[MySingleView_AppDelegate init] apparently gets a segv that Mono thinks is a managed null reference exception but we're still in GC Safe at that point. So we go into mono_exception_new_by_name and all the way to mono_runtime_class_init_full in GC Safe mode.

I'm not clear on why we think the segv is in managed code. (I would expect some kind of native-to-managed wrapper on the stack after -[MySingleView_AppDelegate init])

But probably what we should do is transition to GC Unsafe in handle_signal_exception.
The other codepaths such as mono_sigint_signal_handler and mono_sigfpe_signal_handler do explicitly transition with MONO_ENTER_GC_UNSAFE_UNBALANCED.
That actually looks ok, but not sufficient - since mono_arch_handle_exception will setup handle_signal_exception to be called when the signal handler returns, the signal handler will return from mono_arch_handle_exception and run MONO_EXIT_GC_UNSAFE_UNBALANCED which will undo the transition. So handle_signal_exception will be back in GC Safe.

And in any case mono_sigsegv_signal_handler doesn't do any transition at all. So in that if the signal happened while we were in GC Safe, we'll just stay in GC Safe even if we arrange for handle_signal_exception to be called.

tl;dr I think handle_signal_exception needs GC Unsafe transitions...

@simonrozsival
Copy link
Member Author

@lambdageek it was .NET 8

@lambdageek
Copy link
Member

@simonrozsival is it using the new managed registrar?

@simonrozsival
Copy link
Member Author

@lambdageek yes, I forgot to mention that. I will try the other registrars and see if it's just the new managed registrar.

lambdageek added a commit to lambdageek/runtime that referenced this issue Jul 5, 2023
When the runtime needs to turn some kinds of signals into managed
exceptions (for example: SIGINT turns into
`new ExecutionEngineException ("Interrupted (SIGINT)")`, and some
SIGFPE turn into `DivideByZeroException`, and some SIGSEGV turn into a
`NullReferenceException`) instead of unwinding the stack from inside a
signal handler it instead adjusts the normal stack so that when the
signal handler returns, execution will resume in
`handle_signal_exception`.

That means that if the runtime was in GC Safe mode when the signal
was raised, even if the signal handler code transitions to GC Unsafe
mode, by the time the `handle_signal_exception` runs, we will have
undone the GC Unsafe transition and will be back in GC Safe.

That means if the code in `handle_signal_exception` (notably
`mono_handle_exception`) calls anything that tries to do a transition
to GC Safe, we may get an assertion.

Fixes dotnet#88405
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 5, 2023
@lambdageek
Copy link
Member

ok, so in that case I think one of those -[MySingleView_AppDelegate init] on the stack is an UnmanagedCallersOnly wrapper. so if it SEGVs for some reason I bet we think the whole thing is a managed method even if we haven't done the GC Safe -> GC Unsafe transition yet.

(I'm not sure why we would SEGV there before doing the transition)

@simonrozsival I opened a PR to fix the assertion, but I'm pretty sure you're just going to start getting unhandled NullReferenceExceptions from -[MySingleView_AppDelegate init]. I have no idea why that would be. I guess I would suggest using a native debugger and stepping through -[MySingleView_AppDelegate init] instruction by instruction to try and figure out what goes wrong

@lambdageek
Copy link
Member

lambdageek commented Jul 5, 2023

I'm not very confident my PR is the right fix. it might be better to assert in handle_signal_exception that we're in GC Unsafe mode. if we're not, something suspicious is happening and we might be better off just crashing as early as we can

lambdageek added a commit to lambdageek/runtime that referenced this issue Jul 17, 2023
lambdageek added a commit that referenced this issue Jul 18, 2023
When the runtime needs to turn some kinds of signals into managed
exceptions (for example: SIGINT turns into
`new ExecutionEngineException ("Interrupted (SIGINT)")`, and some
SIGFPE turn into `DivideByZeroException`, and some SIGSEGV turn into a
`NullReferenceException`) instead of unwinding the stack from inside a
signal handler it instead adjusts the normal stack so that when the
signal handler returns, execution will resume in
`handle_signal_exception`.

That means that if the runtime was in GC Safe mode when the signal
was raised, even if the signal handler code transitions to GC Unsafe
mode, by the time the `handle_signal_exception` runs, we will have
undone the GC Unsafe transition and will be back in GC Safe.

That means if the code in `handle_signal_exception` (notably
`mono_handle_exception`) calls anything that tries to do a transition
to GC Safe, we may get an assertion.

Fixes #88405
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jul 18, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Aug 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-VM-threading-mono os-maccatalyst MacCatalyst OS runtime-mono specific to the Mono runtime
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants