Crash on release of object on High Sierra

Hi all,

I've only been able to reproduce it on the ClassicAPI, so I'm not getting my hopes high on this one. But I'm getting that weird crash (while easy to reproduce, I can't yet pinpoint what could specifically be the issue) that seems to happen on the release of objects. Or at least that's what the stack trace leads me to believe. Here is said stack trace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) MonoMac.Foundation.NSObject.xamarin_release_managed_ref (intptr,MonoMac.Foundation.NSObject) <0x00012>
  at MonoMac.Foundation.NSObject.ReleaseManagedRef () [0x00008] in /Users/builder/data/lanes/4991/8a391069/source/xamarin-macios/src/Foundation/NSObject2.cs:208
  at MonoMac.Foundation.NSObject/NSObject_Disposer.Drain (MonoMac.Foundation.NSObject) [0x00067] in /Users/builder/data/lanes/4991/8a391069/source/xamarin-macios/src/Foundation/NSObject2.cs:784
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) [0x00051] in <ad88d4f2c5174527b07cc6b4766083a1>:0
  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[]) <0x00015>
  at MonoMac.AppKit.NSApplication.Main (string[]) [0x00041] in /Users/builder/data/lanes/4991/8a391069/source/xamarin-macios/src/AppKit/NSApplication.cs:100
  at Client.BaseMacClient.Run () [0x0000c] in /Users/Devolutions/workspace/RDMOX/Mac/RemoteDesktopManager/Core/Client/BaseMacClient.cs:51
  at Client.BaseMacClient.Startup () [0x00010] in /Users/Devolutions/workspace/RDMOX/Mac/RemoteDesktopManager/Core/Client/BaseMacClient.cs:44
  at Client.BaseMacClient.Startup<T_REF> () [0x00027] in /Users/Devolutions/workspace/RDMOX/Mac/RemoteDesktopManager/Core/Client/BaseMacClient.cs:39
  at Client.BaseMacClient.Startup<T_REF> (string[]) [0x00007] in /Users/Devolutions/workspace/RDMOX/Mac/RemoteDesktopManager/Core/Client/BaseMacClient.cs:22
  at PasswordVaultManager.Client.Main (string[]) [0x0013e] in /Users/Devolutions/workspace/RDMOX/Mac/RemoteDesktopManager/Clients/PasswordVaultManager/Client.cs:174
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) [0x00051] in <cf85f8e734f447d5b93a0333fd1bfd27>:0

I'll just leave this here in case this is actually a known issue or if someone else has been having this issue.

I did find a similar bug: https://bugzilla.xamarin.com/show_bug.cgi?id=45637

But it kind of date and I don't think there was any mention of the OS.

In the mean time, I'll just push harder toward releasing the UnifiedAPI version of our app since this issue is quite worrying.

Best regards,

Best Answer

Answers

  • XavierFortinXavierFortin USMember ✭✭

    Hi @ChrisHamons ,

    I'm getting this in the UnifiedAPI too (if maybe less frequently, it's hard to say). Is there any way to somehow debug this.

    It seems to be related to observer somehow. Here's the full stacktrace (with its Native part):

    Stacktrace:
      at <unknown> <0xffffffff>
      at (wrapper managed-to-native) Foundation.NSObject.xamarin_release_managed_ref (intptr,Foundation.NSObject) [0x00008] in <e0dde63a2c804cbc8ca7de25e282c218>:0
      at Foundation.NSObject.ReleaseManagedRef () [0x00008] in <e0dde63a2c804cbc8ca7de25e282c218>:0
      at Foundation.NSObject/NSObject_Disposer.Drain (Foundation.NSObject) [0x00067] in <e0dde63a2c804cbc8ca7de25e282c218>:0
      at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) [0x00021] in <e0dde63a2c804cbc8ca7de25e282c218>:0
      at <unknown> <0xffffffff>
      at (wrapper managed-to-native) AppKit.NSApplication.NSApplicationMain (int,string[]) [0x0005a] in <e0dde63a2c804cbc8ca7de25e282c218>:0
      at AppKit.NSApplication.Main (string[]) [0x00041] in <e0dde63a2c804cbc8ca7de25e282c218>:0
      at A.cf7391eac3051280550fc2b95b031ac78.cf0dc1cfd9b511309d6fbd24be6ac2187 () [0x0000d] in <a3d184e2bc744eb4a9f5c0eab84b552f>:0
      at A.cf7391eac3051280550fc2b95b031ac78.cf80ac4075cce562eb8254151c47d3e24 () [0x00011] in <a3d184e2bc744eb4a9f5c0eab84b552f>:0
      at A.cf7391eac3051280550fc2b95b031ac78.cf80ac4075cce562eb8254151c47d3e24<ceaa9d1a76410934033f88a1b7444f6db_REF> () [0x00039] in <a3d184e2bc744eb4a9f5c0eab84b552f>:0
      at A.cf7391eac3051280550fc2b95b031ac78.cf80ac4075cce562eb8254151c47d3e24<ceaa9d1a76410934033f88a1b7444f6db_REF> (string[]) [0x00006] in <a3d184e2bc744eb4a9f5c0eab84b552f>:0
      at A.cdd520c65dd8e922550634a1652d62e71.cd00ca868e3a2e07e1a60509ada71b4d9 (string[]) [0x0017f] in <286c7d23818147918a0e2862ebfbde13>:0
      at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) [0x00051] in <286c7d23818147918a0e2862ebfbde13>:0
    Native stacktrace:
        0   RemoteDesktopManager                0x000000010d2954e1 mono_handle_native_crash + 257
        1   RemoteDesktopManager                0x000000010d215196 altstack_handle_and_restore + 70
        2   libobjc.A.dylib                     0x00007fff6acd7c3e object_isClass + 31
        3   Foundation                          0x00007fff461dc119 KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED + 58
        4   Foundation                          0x00007fff461db026 NSKeyValueWillChangeWithPerThreadPendingNotifications + 294
        5   AppKit                              0x00007fff41576ddb -[NSView _recacheEffectiveAppearance] + 292
        6   AppKit                              0x00007fff41575f06 -[NSView _setSuperview:] + 747
        7   AppKit                              0x00007fff4157ac7d -[NSView removeFromSuperview] + 252
        8   AppKit                              0x00007fff4168e740 -[NSView removeFromSuperviewWithoutNeedingDisplay] + 38
        9   AppKit                              0x00007fff41e3d690 -[NSView _finalize] + 1068
        10  AppKit                              0x00007fff41588a62 -[NSView dealloc] + 164
        11  RemoteDesktopManager                0x000000010d1a92bb xamarin_invoke_objc_method_implementation + 59
        12  RemoteDesktopManager                0x000000010d1a955b xamarin_release_trampoline + 155
        13  RemoteDesktopManager                0x000000010d1a5d6b xamarin_release_managed_ref + 139
        14  ???                                 0x00000001219d4935 0x0 + 4858923317
        15  ???                                 0x00000001239265f1 0x0 + 4891764209
        16  RemoteDesktopManager                0x000000010d2a67c8 mono_jit_runtime_invoke + 1288
        17  RemoteDesktopManager                0x000000010d371548 do_runtime_invoke + 88
        18  RemoteDesktopManager                0x000000010d371456 mono_runtime_invoke + 102
        19  RemoteDesktopManager                0x000000010d1ad6ce xamarin_invoke_trampoline + 5662
        20  RemoteDesktopManager                0x000000010d1ae53d xamarin_arch_trampoline + 189
        21  RemoteDesktopManager                0x000000010d1af9d1 xamarin_x86_64_common_trampoline + 110
        22  Foundation                          0x00007fff460cc1c5 __NSThreadPerformPerform + 334
        23  CoreFoundation                      0x00007fff43fd1721 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
        24  CoreFoundation                      0x00007fff4408b0ac __CFRunLoopDoSource0 + 108
        25  CoreFoundation                      0x00007fff43fb4260 __CFRunLoopDoSources0 + 208
        26  CoreFoundation                      0x00007fff43fb36dd __CFRunLoopRun + 1293
        27  CoreFoundation                      0x00007fff43fb2f43 CFRunLoopRunSpecific + 483
        28  HIToolbox                           0x00007fff432cae26 RunCurrentEventLoopInMode + 286
        29  HIToolbox                           0x00007fff432caa9f ReceiveNextEventCommon + 366
        30  HIToolbox                           0x00007fff432ca914 _BlockUntilNextEventMatchingListInModeWithFilter + 64
        31  AppKit                              0x00007fff41595f5f _DPSNextEvent + 2085
        32  AppKit                              0x00007fff41d2bb4c -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044
        33  AppKit                              0x00007fff4158ad6d -[NSApplication run] + 764
        34  AppKit                              0x00007fff41559f1a NSApplicationMain + 804
        35  ???                                 0x0000000120c489d1 0x0 + 4844718545
        36  ???                                 0x0000000120c48853 0x0 + 4844718163
        37  ???                                 0x0000000113f944c9 0x0 + 4630070473
        38  RemoteDesktopManager                0x000000010d2a67c8 mono_jit_runtime_invoke + 1288
        39  RemoteDesktopManager                0x000000010d371548 do_runtime_invoke + 88
        40  RemoteDesktopManager                0x000000010d374b89 do_exec_main_checked + 137
        41  RemoteDesktopManager                0x000000010d20c3ef mono_jit_exec + 287
        42  RemoteDesktopManager                0x000000010d20ec7b mono_main + 9307
        43  RemoteDesktopManager                0x000000010d1aff2e xamarin_main + 1182
        44  RemoteDesktopManager                0x000000010d1b0e84 main + 36
        45  libdyld.dylib                       0x00007fff6b8c6115 start + 1
        46  ???                                 0x0000000000000001 0x0 + 1
    =================================================================
    Got a SIGSEGV while executing native code. This usually indicates
    a fatal error in the mono runtime or one of the native libraries 
    used by your application.
    =================================================================
    

    Is there a preferred method in Xamarin.Mac to register observers? Maybe this is the issue.

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    So "KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED" is telling you what happened.

    but let's walk a rough clean up of the stack

    Boom (crash)
    Foundation isClass check
    KVO Notification
    View RemoveFromSuperView
    NSView dealloc (so it appears to be a view or holding on to a view)
    Someone called dealloc
    JIT code we can't see into
    Call into JIT code
    EventLoop Spins
    [NSApplicationMain run]
    Main ()

    which says to me - " We're cleaning up something and the thing has a notification object that got cleaned up from underneath us.

    There are a number of ways I'd attack this problem.

    • Turn on AOT if possible. It'll really clean up the section of JIT in the middle and may make the issue obvious
    • Try running your application under Instruments's Zombie template. It's normally pretty could about pointing out the guilty victim, so you can figure out who killed it early.
    • Try running your application with NSZombieEnabled=1 NSZombieEnabled=1 ./Foo.app/Contents/MacOS/Foo which squawks better in cases like this
    • See if you can figure out what NSView we're cleaning up. Maybe shove it in lldb or have your NSViews dump their name\position when removed from superview? That should help you figure out what notification is causing issues.

    Cocoa notification mechanism is handy, and can make data binding easier but it assumes strongly that your memory management technique is flawless. If you make mistakes, it can cause crashes like this (in ObjC as well as C#).

    This is for Obj-c and doesn't completely apply, but may be useful to read: http://inessential.com/2015/05/21/how_not_to_crash_3_nsnotification

  • XavierFortinXavierFortin USMember ✭✭

    Hi Chris and thanks for the quick answer.

    Is there any way to ignore assembly when AOT? I'm getting this error:

    Could not AOT the assembly '/Path/To/Application/Bundle/Contents/MonoBundle/System.ServiceModel.Discovery.dll' (MM3001)

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    Yep. Here's the section from /Library/Frameworks/Xamarin.Mac.framework/Commands/mmp --help

      --aot[=VALUE]          Specify assemblies that should be AOT compiled
                               - none - No AOT (default)
                               - all - Every assembly in MonoBundle
                               - core - Xamarin.Mac, System, mscorlib
                               - sdk - Xamarin.Mac.dll and BCL assemblies
                               - |hybrid after option enables hybrid AOT which
                               allows IL stripping but is slower (only valid
                               for 'all')
                                - Individual files can be included for AOT via +
                               FileName.dll and excluded via -FileName.dll
    
                               Examples:
                                 --aot:all,-MyAssembly.dll
                                 --aot:core,+MyOtherAssembly.dll,-mscorlib.dll
    

    so adding to the end of your aot argument ,-System.ServiceModel.Discovery.dll might be enough.

  • XavierFortinXavierFortin USMember ✭✭

    Weird, I still get the same stack trace with the JIT code after applying AOT:

    Native stacktrace:
    
        0   RemoteDesktopManager                0x000000010cb374f1 mono_handle_native_crash + 257
        1   RemoteDesktopManager                0x000000010cab22c6 altstack_handle_and_restore + 70
        2   libobjc.A.dylib                     0x00007fff55c68c3e object_isClass + 31
        3   Foundation                          0x00007fff3040ad61 KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED + 58
        4   Foundation                          0x00007fff30409c96 NSKeyValueWillChangeWithPerThreadPendingNotifications + 294
        5   AppKit                              0x00007fff2b692a97 -[NSView _recacheEffectiveAppearance] + 292
        6   AppKit                              0x00007fff2b691bc2 -[NSView _setSuperview:] + 747
        7   AppKit                              0x00007fff2b696939 -[NSView removeFromSuperview] + 252
        8   AppKit                              0x00007fff2b7aa480 -[NSView removeFromSuperviewWithoutNeedingDisplay] + 38
        9   AppKit                              0x00007fff2bf59a44 -[NSView _finalize] + 1068
        10  AppKit                              0x00007fff2b6a471e -[NSView dealloc] + 164
        11  RemoteDesktopManager                0x000000010ca4641b xamarin_invoke_objc_method_implementation + 59
        12  RemoteDesktopManager                0x000000010ca466bb xamarin_release_trampoline + 155
        13  RemoteDesktopManager                0x000000010ca42e0b xamarin_release_managed_ref + 139
        14  ???                                 0x00000001210a8c41 0x0 + 4849306689
        15  ???                                 0x00000001265d2453 0x0 + 4938605651
        16  RemoteDesktopManager                0x000000010cb49e2a mono_jit_runtime_invoke + 1338
        17  RemoteDesktopManager                0x000000010cc169f4 do_runtime_invoke + 84
        18  RemoteDesktopManager                0x000000010cc16970 mono_runtime_invoke + 208
        19  RemoteDesktopManager                0x000000010ca4a97c xamarin_invoke_trampoline + 5996
        20  RemoteDesktopManager                0x000000010ca4b7ed xamarin_arch_trampoline + 189
        21  RemoteDesktopManager                0x000000010ca4cc81 xamarin_x86_64_common_trampoline + 110
        22  Foundation                          0x00007fff302fa2b5 __NSThreadPerformPerform + 334
        23  CoreFoundation                      0x00007fff2e131c81 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
        24  CoreFoundation                      0x00007fff2e1eb69c __CFRunLoopDoSource0 + 108
        25  CoreFoundation                      0x00007fff2e1146e0 __CFRunLoopDoSources0 + 208
        26  CoreFoundation                      0x00007fff2e113b5d __CFRunLoopRun + 1293
        27  CoreFoundation                      0x00007fff2e1133c3 CFRunLoopRunSpecific + 483
        28  HIToolbox                           0x00007fff2d3ffd86 RunCurrentEventLoopInMode + 286
        29  HIToolbox                           0x00007fff2d3ff9ff ReceiveNextEventCommon + 366
        30  HIToolbox                           0x00007fff2d3ff874 _BlockUntilNextEventMatchingListInModeWithFilter + 64
        31  AppKit                              0x00007fff2b6b1c17 _DPSNextEvent + 2085
        32  AppKit                              0x00007fff2be47f04 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044
        33  AppKit                              0x00007fff2b6a6a29 -[NSApplication run] + 764
        34  AppKit                              0x00007fff2b675c02 NSApplicationMain + 804
        35  ???                                 0x00000001202a31b0 0x0 + 4834603440
        36  ???                                 0x00000001202a2df3 0x0 + 4834602483
        37  ???                                 0x000000010eb96de9 0x0 + 4542000617
        38  RemoteDesktopManager                0x000000010cb49e2a mono_jit_runtime_invoke + 1338
        39  RemoteDesktopManager                0x000000010cc169f4 do_runtime_invoke + 84
        40  RemoteDesktopManager                0x000000010cc1a029 do_exec_main_checked + 137
        41  RemoteDesktopManager                0x000000010caa944f mono_jit_exec + 287
        42  RemoteDesktopManager                0x000000010caabd0d mono_main + 9325
        43  RemoteDesktopManager                0x000000010ca4d65e xamarin_main + 1182
        44  RemoteDesktopManager                0x000000010ca4e5b4 main + 36
        45  libdyld.dylib                       0x00007fff56881015 start + 1
    

    I'll try one of the other methods though. I think just getting the name of the view would be a good start.

    By the way, out of curiosity, I looked into the app bundle build with AOT and in Contents/MonoBundle, for each dll, there is its equivalent .dylib. Are the .dll still needed in the bundle or are the dylib containing all that is needed?

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    So there are a number of instances where we use JIT even if you AOT, since it isn't a full AOT (unless you turn on hybrid), so some JIT frames are not totally unexpected. However, I don't see any AOT bits.

    You could run with MONO_LOG_LEVEL=debug MONO_LOG_MASK="asm,dll" and see if it points out why AOT isn't being used.

    To answer your second question, we still use the dlls for metadata and JIT some troublesome code locations, where it would be much slower if we had to AOT. If you enable hybrid (shown in the help I posted above), you can get away with that, but there is a performance penalty.

Sign In or Register to comment.