Bug 60634 - Assertion failure 'align > 0' happening as of d15-5
Summary: Assertion failure 'align > 0' happening as of d15-5
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: JIT (show other bugs)
Version: 5.8 (2017-10)
Hardware: PC Mac OS
: --- normal
Target Milestone: 15.6
Assignee: Zoltan Varga
URL:
Depends on:
Blocks:
 
Reported: 2017-11-13 01:38 UTC by Jim Borden
Modified: 2018-01-05 13:28 UTC (History)
11 users (show)

Tags: bugpool-archive
Is this bug a regression?: Yes
Last known good build: mono/2017-04


Attachments
Repro project (3.91 MB, application/zip)
2017-11-13 01:38 UTC, Jim Borden
Details
Sample database for use with repro project (2.31 MB, application/zip)
2017-11-13 01:43 UTC, Jim Borden
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Jim Borden 2017-11-13 01:38:32 UTC
Created attachment 25657 [details]
Repro project

I wasn't sure if this belonged in Library or Runtime, but I have a pet project that I am working on that needed a feature (AppContext stuff) that was present in 4.x but not in the latest stable.  However, when I upgraded I was faced with the hard crash at the bottom of this message.  The odd thing is, it tells me that the crash occurs at a frame after QueryViewModel.cs:141, but I cannot step into that line before the crash happens (even with a breakpoint on the supposed first line of the next frame) so I don't know exactly what is causing it.  There is native code (C / C++) involved here but as far as I can tell, it is not reached between this line and the breakpoint.  If you want to view the native code involved, it is @ https://github.com/couchbase/couchbase-lite-core/tree/839a733b27a5b91db0e75bb8465cfdd5a8c24fd0.  The source for Couchbase.Lite is @ https://github.com/couchbase/couchbase-lite-net/tree/ed2bafb3d7dae1157cc65cfeb9f5e9db808b4cb2.  In particular, the place where the crash occurs is between the noted line and https://github.com/couchbase/couchbase-lite-net/blob/ed2bafb3d7dae1157cc65cfeb9f5e9db808b4cb2/src/Couchbase.Lite/API/Database/Database.cs#L179 (In other words, if I set a breakpoint at that line, it never gets hit and instead a crash happens)

> 2017-11-13 09:46:29.500 LiteViewer[38567:4381949] error: * Assertion at /Users/builder/data/lanes/5489/25c6ba1e/source/xamarin-macios/external/mono/mono/mini/memory-access.c:29, condition `align > 0' not met
> Stacktrace:

>   at <unknown> <0xffffffff>
>   at LiteViewerCore.ViewModels.QueryViewModel..ctor (string) [0x0004c] in /Users/borrrden/Development/LiteViewer/LiteViewerCore/ViewModels/QueryViewModel.cs:141
>   at LiteViewer.Mac.Pages.QueryPage.OnOpenClicked (object,System.EventArgs) [0x0002e] in /Users/borrrden/Development/LiteViewer/LiteViewer.Mac/Pages/QueryPage.xaml.cs:38
>   at Xamarin.Forms.Button.SendClicked () [0x00028] in <e3c6df132acf467b8454c1ce7cb4c77d>:0
>   at Xamarin.Forms.Platform.MacOS.ButtonRenderer.OnButtonActivated (object,System.EventArgs) [0x0000b] in <f002609f3b3c4226b5aa0a4716f2f0dc>:0
>   at AppKit.ActionDispatcher.OnActivated (Foundation.NSObject) [0x00015] in /Users/builder/data/lanes/5489/25c6ba1e/source/xamarin-macios/src/AppKit/ActionDispatcher.cs:49
>   at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (object,intptr,intptr,intptr) [0x00053] in <a9412d675c184f40aac9c60397108ca7>:0
>   at <unknown> <0xffffffff>
>   at (wrapper managed-to-native) AppKit.NSApplication.NSApplicationMain (int,string[]) [0x0005a] in <a9412d675c184f40aac9c60397108ca7>:0
>   at AppKit.NSApplication.Main (string[]) [0x00041] in /Users/builder/data/lanes/5489/25c6ba1e/source/xamarin-macios/src/AppKit/NSApplication.cs:100
>   at LiteViewer.Mac.MainClass.Main (string[]) [0x00017] in /Users/borrrden/Development/LiteViewer/LiteViewer.Mac/Main.cs:11
>   at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) [0x00051] in <ff8201961924483487f69f592285d0d4>:0

> Native stacktrace:

> 	0   LiteViewer                          0x000000010c74b551 mono_handle_native_crash + 257
> 	1   libsystem_platform.dylib            0x00007fffd5740b3a _sigtramp + 26
> 	2   ???                                 0x00007fff535cb520 0x0 + 140734591972640
> 	3   libsystem_c.dylib                   0x00007fffd55c5420 abort + 129
> 	4   LiteViewer                          0x000000010c65ab90 _ZL12log_callbackPKcS0_S0_iPv + 64
> 	5   LiteViewer                          0x000000010c904333 monoeg_g_logv + 83
> 	6   LiteViewer                          0x000000010c90454f monoeg_assertion_message + 143
> 	7   LiteViewer                          0x000000010c6d8450 mini_emit_memset + 832
> 	8   LiteViewer                          0x000000010c6de872 mini_emit_initobj + 274
> 	9   LiteViewer                          0x000000010c6ef96e mono_method_to_ir + 61310
> 	10  LiteViewer                          0x000000010c76670d mini_method_compile + 2893
> 	11  LiteViewer                          0x000000010c769929 mono_jit_compile_method_inner + 761
> 	12  LiteViewer                          0x000000010c758bf3 mono_jit_compile_method_with_opt + 1347
> 	13  LiteViewer                          0x000000010c75f4f0 common_call_trampoline + 1264
> 	14  LiteViewer                          0x000000010c75efc9 mono_magic_trampoline + 73
> 	15  ???                                 0x000000010ceb439e 0x0 + 4511712158
> 	16  ???                                 0x0000000118792433 0x0 + 4705559603
> 	17  ???                                 0x000000011878c943 0x0 + 4705536323
> 	18  ???                                 0x000000011878c42e 0x0 + 4705535022
> 	19  LiteViewer                          0x000000010c75c838 mono_jit_runtime_invoke + 1288
> 	20  LiteViewer                          0x000000010c8275b8 do_runtime_invoke + 88
> 	21  LiteViewer                          0x000000010c827530 mono_runtime_invoke + 208
> 	22  LiteViewer                          0x000000010c92538e _ZL30native_to_managed_trampoline_9P11objc_objectP13objc_selectorPP11_MonoMethodP8NSObjectj + 382
> 	23  LiteViewer                          0x000000010c925208 -[__monomac_internal_ActionDispatcher __monomac_internal_ActionDispatcher_activated:] + 56
> 	24  libsystem_trace.dylib               0x00007fffd57633a7 _os_activity_initiate_impl + 53
> 	25  AppKit                              0x00007fffbe020721 -[NSApplication(NSResponder) sendAction:to:from:] + 456
> 	26  AppKit                              0x00007fffbdb04cc4 -[NSControl sendAction:to:] + 86
> 	27  AppKit                              0x00007fffbdb04bec __26-[NSCell _sendActionFrom:]_block_invoke + 136
> 	28  libsystem_trace.dylib               0x00007fffd57633a7 _os_activity_initiate_impl + 53
> 	29  AppKit                              0x00007fffbdb04b44 -[NSCell _sendActionFrom:] + 128
> 	30  AppKit                              0x00007fffbdb47539 -[NSButtonCell _sendActionFrom:] + 98
> 	31  libsystem_trace.dylib               0x00007fffd57633a7 _os_activity_initiate_impl + 53
> 	32  AppKit                              0x00007fffbdb03426 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2481
> 	33  AppKit                              0x00007fffbdb47272 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 798
> 	34  AppKit                              0x00007fffbdb01ddb -[NSControl mouseDown:] + 832
> 	35  AppKit                              0x00007fffbe19c24f -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 6341
> 	36  AppKit                              0x00007fffbe198a6c -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 1942
> 	37  AppKit                              0x00007fffbe197f0a -[NSWindow(NSEventRouting) sendEvent:] + 541
> 	38  AppKit                              0x00007fffbe01c681 -[NSApplication(NSEvent) sendEvent:] + 1145
> 	39  AppKit                              0x00007fffbd897427 -[NSApplication run] + 1002
> 	40  AppKit                              0x00007fffbd861e0e NSApplicationMain + 1237
> 	41  ???                                 0x0000000112573108 0x0 + 4602671368
> 	42  ???                                 0x0000000112572cc3 0x0 + 4602670275
> 	43  LiteViewer                          0x000000010c75c838 mono_jit_runtime_invoke + 1288
> 	44  LiteViewer                          0x000000010c8275b8 do_runtime_invoke + 88
> 	45  LiteViewer                          0x000000010c82abf9 do_exec_main_checked + 137
> 	46  LiteViewer                          0x000000010c6c246f mono_jit_exec + 287
> 	47  LiteViewer                          0x000000010c6c4cfb mono_main + 9307
> 	48  LiteViewer                          0x000000010c665fae xamarin_main + 1182
> 	49  LiteViewer                          0x000000010c666f04 main + 36
> 	50  libdyld.dylib                       0x00007fffd5531235 start + 1

> Debug info from gdb:

> (lldb) command source -s 0 '/tmp/mono-gdb-commands.c4orNf'
> Executing commands in '/tmp/mono-gdb-commands.c4orNf'.
> (lldb) process attach --pid 38567
> Process 38567 stopped
> * thread #1, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
>     frame #0: 0x00007fffd56603ee libsystem_kernel.dylib`__wait4 + 10
> libsystem_kernel.dylib`__wait4:
> ->  0x7fffd56603ee <+10>: jae    0x7fffd56603f8            ; <+20>
>     0x7fffd56603f0 <+12>: movq   %rax, %rdi
>     0x7fffd56603f3 <+15>: jmp    0x7fffd5658cd4            ; cerror
>     0x7fffd56603f8 <+20>: retq   
> Target 0: (LiteViewer) stopped.

> Executable module set to "/Users/borrrden/Development/LiteViewer/LiteViewer.Mac/bin/Debug/LiteViewer.app/Contents/MacOS/LiteViewer".
> Architecture set to: x86_64h-apple-macosx.
> (lldb) thread list
> Process 38567 stopped
> * thread #1: tid = 0x42dcfd, 0x00007fffd56603ee libsystem_kernel.dylib`__wait4 + 10, name = 'tid_307', queue = 'com.apple.main-> thread', stop reason = signal SIGSTOP
>   thread #2: tid = 0x42dd07, 0x00007fffd565fbf2 libsystem_kernel.dylib`__psynch_cvwait + 10, queue = 'TBrowserViewDataSource'
>   thread #3: tid = 0x42dd0c, 0x00007fffd565fbf2 libsystem_kernel.dylib`__psynch_cvwait + 10, name = 'SGen worker'
>   thread #4: tid = 0x42dd0f, 0x00007fffd5658386 libsystem_kernel.dylib`semaphore_wait_trap + 10, name = 'Finalizer'
>   thread #5: tid = 0x42dd10, 0x00007fffd565fdf6 libsystem_kernel.dylib`__recvfrom + 10, name = 'Debugger agent'
>   thread #6: tid = 0x42dd2f, 0x00007fffd565834a libsystem_kernel.dylib`mach_msg_trap + 10, name = 'com.apple.NSEventThread'
>   thread #7: tid = 0x42dd7b, 0x00007fffd566044e libsystem_kernel.dylib`__workq_kernreturn + 10
>   thread #8: tid = 0x42e294, 0x00007fffd566044e libsystem_kernel.dylib`__workq_kernreturn + 10
> (lldb) thread backtrace all
> * thread #1, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
>   * frame #0: 0x00007fffd56603ee libsystem_kernel.dylib`__wait4 + 10
>     frame #1: 0x000000010c74b5de LiteViewer`mono_handle_native_crash(signal="SIGABRT", ctx=<unavailable>, info=<unavailable>) at mini-exceptions.c:2720 [opt]
>     frame #2: 0x00007fffd5740b3a libsystem_platform.dylib`_sigtramp + 26
>     frame #3: 0x00007fffd565fd43 libsystem_kernel.dylib`__pthread_kill + 11
>     frame #4: 0x00007fffd574d457 libsystem_pthread.dylib`pthread_kill + 90
>     frame #5: 0x00007fffd55c5420 libsystem_c.dylib`abort + 129
>     frame #6: 0x000000010c65ab90 LiteViewer`log_callback(log_domain=0x0000000000000000, log_level="error", message="* Assertion at /Users/builder/data/lanes/5489/25c6ba1e/source/xamarin-macios/external/mono/mono/mini/memory-access.c:29, condition `align > 0' not met\n", fatal=4, user_data=0x0000000000000000) at runtime.m:1206
>     frame #7: 0x000000010c904333 LiteViewer`monoeg_g_logv(log_domain=0x0000000000000000, log_level=G_LOG_LEVEL_ERROR, format=<unavailable>, args=<unavailable>) at goutput.c:115 [opt]
>     frame #8: 0x000000010c90454f LiteViewer`monoeg_assertion_message(format=<unavailable>) at goutput.c:135 [opt]
>     frame #9: 0x000000010c6d8450 LiteViewer`mini_emit_memset(cfg=0x00007fa4b32ffe00, destreg=106, offset=0, size=8, val=<unavailable>, align=1398586268) at memory-access.c:29 [opt]
>     frame #10: 0x000000010c6de872 LiteViewer`mini_emit_initobj(cfg=0x00007fa4b32ffe00, dest=0x00007fa4b3417028, ip=<unavailable>, klass=<unavailable>) at method-to-ir.c:2930 [opt]
>     frame #11: 0x000000010c6ef96e LiteViewer`mono_method_to_ir(cfg=<unavailable>, method=<unavailable>, start_bblock=0x00007fa4b340da70, end_bblock=0x00007fa4b340dba8, return_var=0x0000000000000000, inline_args=0x0000000000000035, inline_offset=<unavailable>, is_virtual_call=<unavailable>) at method-to-ir.c:12408 [opt]
>     frame #12: 0x000000010c76670d LiteViewer`mini_method_compile(method=<unavailable>, opts=370239999, domain=0x00007fa4b5100500, flags=JIT_FLAG_RUN_CCTORS, parts=0, aot_method_index=-1) at mini.c:3442 [opt]
>     frame #13: 0x000000010c769929 LiteViewer`mono_jit_compile_method_inner(method=0x00007fa4b33f4c60, target_domain=0x00007fa4b5100500, opt=370239999, error=0x00007fff535cc248) at mini.c:4167 [opt]
>     frame #14: 0x000000010c758bf3 LiteViewer`mono_jit_compile_method_with_opt(method=0x00007fa4b33f4c60, opt=370239999, jit_only=0, error=<unavailable>) at mini-runtime.c:2129 [opt]
>     frame #15: 0x000000010c75f4f0 LiteViewer`common_call_trampoline(regs=0x00007fff535cc328, code="A\xbb", m=0x00007fa4b33f4c60, vt=<unavailable>, vtable_slot=<unavailable>, error=<unavailable>) at mini-trampolines.c:708 [opt]
>     frame #16: 0x000000010c75efc9 LiteViewer`mono_magic_trampoline(regs=<unavailable>, code=<unavailable>, arg=<unavailable>, tramp=<unavailable>) at mini-trampolines.c:838 [opt]
>     frame #17: 0x000000010ceb439e
>     frame #18: 0x0000000118792433
>     frame #19: 0x000000011878c943
>     frame #20: 0x000000011878c42e
>     frame #21: 0x000000010c75c838 LiteViewer`mono_jit_runtime_invoke(method=0x0000000000000000, obj=<unavailable>, params=0x00007fff535cccf0, exc=0x0000000000000000, error=<unavailable>) at mini-runtime.c:2791 [opt]
>     frame #22: 0x000000010c8275b8 LiteViewer`do_runtime_invoke(method=0x00007fa4b6015738, obj=0x000000010d070dd8, params=0x00007fff535cccf0, exc=0x0000000000000000, error=0x00007fff535ccbd8) at object.c:2862 [opt]
>     frame #23: 0x000000010c827530 LiteViewer`mono_runtime_invoke [inlined] mono_runtime_invoke_checked(method=<unavailable>, obj=0x000000010d070dd8, params=0x00007fff535cccf0, error=0x0000000100000000) at object.c:3016 [opt]
>     frame #24: 0x000000010c8274ef LiteViewer`mono_runtime_invoke(method=0x00007fa4b6015738, obj=0x000000010d070dd8, params=0x00007fff535cccf0, exc=<unavailable>) at object.c:2917 [opt]
>     frame #25: 0x000000010c92538e LiteViewer`native_to_managed_trampoline_9(self=0x0000618000a24a00, _cmd="__monomac_internal_ActionDispatcher_activated:", managed_method_ptr=0x000000010cae8da8, p0=0x0000618000151a90, token_ref=2385) at Xamarin.Mac.registrar.mobile.x86_64.m:398
>     frame #26: 0x000000010c925208 LiteViewer`::-[__monomac_internal_ActionDispatcher __monomac_internal_ActionDispatcher_activated:](self=0x0000618000a24a00, _cmd="__monomac_internal_ActionDispatcher_activated:", p0=0x0000618000151a90) at Xamarin.Mac.registrar.mobile.x86_64.m:28121
>     frame #27: 0x00007fffd57633a7 libsystem_trace.dylib`_os_activity_initiate_impl + 53
>     frame #28: 0x00007fffbe020721 AppKit`-[NSApplication(NSResponder) sendAction:to:from:] + 456
>     frame #29: 0x00007fffbdb04cc4 AppKit`-[NSControl sendAction:to:] + 86
>     frame #30: 0x00007fffbdb04bec AppKit`__26-[NSCell _sendActionFrom:]_block_invoke + 136
>     frame #31: 0x00007fffd57633a7 libsystem_trace.dylib`_os_activity_initiate_impl + 53
>     frame #32: 0x00007fffbdb04b44 AppKit`-[NSCell _sendActionFrom:] + 128
>     frame #33: 0x00007fffbdb47539 AppKit`-[NSButtonCell _sendActionFrom:] + 98
>     frame #34: 0x00007fffd57633a7 libsystem_trace.dylib`_os_activity_initiate_impl + 53
>     frame #35: 0x00007fffbdb03426 AppKit`-[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2481
>     frame #36: 0x00007fffbdb47272 AppKit`-[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 798
>     frame #37: 0x00007fffbdb01ddb AppKit`-[NSControl mouseDown:] + 832
>     frame #38: 0x00007fffbe19c24f AppKit`-[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 6341
>     frame #39: 0x00007fffbe198a6c AppKit`-[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 1942
>     frame #40: 0x00007fffbe197f0a AppKit`-[NSWindow(NSEventRouting) sendEvent:] + 541
>     frame #41: 0x00007fffbe01c681 AppKit`-[NSApplication(NSEvent) sendEvent:] + 1145
>     frame #42: 0x00007fffbd897427 AppKit`-[NSApplication run] + 1002
>     frame #43: 0x00007fffbd861e0e AppKit`NSApplicationMain + 1237
>     frame #44: 0x0000000112573108
>     frame #45: 0x0000000112572cc3
>     frame #46: 0x000000010c75c838 LiteViewer`mono_jit_runtime_invoke(method=0x0000000000000000, obj=<unavailable>, params=0x00007fff535ce268, exc=0x0000000000000001, error=<unavailable>) at mini-runtime.c:2791 [opt]
>     frame #47: 0x000000010c8275b8 LiteViewer`do_runtime_invoke(method=0x00007fa4b2506dc8, obj=0x0000000000000000, params=0x00007fff535ce268, exc=0x0000000000000000, error=0x00007fff535ce2a8) at object.c:2862 [opt]
>     frame #48: 0x000000010c82abf9 LiteViewer`do_exec_main_checked [inlined] mono_runtime_invoke_checked(method=<unavailable>, obj=<unavailable>, error=<unavailable>) at object.c:3016 [opt]
>     frame #49: 0x000000010c82abb8 LiteViewer`do_exec_main_checked(method=0x00007fa4b2506dc8, args=<unavailable>, error=0x00007fff535ce2a8) at object.c:4690 [opt]
>     frame #50: 0x000000010c6c246f LiteViewer`mono_jit_exec(domain=<unavailable>, assembly=<unavailable>, argc=2, argv=0x0000600000078f20) at driver.g.c:1036 [opt]
>     frame #51: 0x000000010c6c4cfb LiteViewer`mono_main [inlined] main_thread_handler at driver.g.c:1105 [opt]
>     frame #52: 0x000000010c6c4cc5 LiteViewer`mono_main(argc=<unavailable>, argv=<unavailable>) at driver.g.c:2226 [opt]
>     frame #53: 0x000000010c665fae LiteViewer`::xamarin_main(argc=2, argv=0x00007fff535ce5c8, launch_mode=XamarinLaunchModeApp) at launcher.m:662
>     frame #54: 0x000000010c666f04 LiteViewer`main(argc=2, argv=0x00007fff535ce5c8) at launcher.m:680
>     frame #55: 0x00007fffd5531235 libdyld.dylib`start + 1
>     frame #56: 0x00007fffd5531235 libdyld.dylib`start + 1
>   thread #2, queue = 'TBrowserViewDataSource'
>     frame #0: 0x00007fffd565fbf2 libsystem_kernel.dylib`__psynch_cvwait + 10
>     frame #1: 0x00007fffd574b7fa libsystem_pthread.dylib`_pthread_cond_wait + 712
>     frame #2: 0x00007fffcc974759 FinderKit`ModifyDataSourceOnMainThreadSync(FI_TBrowserViewDataSource*, FI_TBVDSChangedNotificationData*, std::__1::function<void ()> const&) + 391
>     frame #3: 0x00007fffcc977b38 FinderKit`__49-[FI_TBrowserViewDataSource closeContainerNodes:]_block_invoke + 264
>     frame #4: 0x00007fffd5504524 libdispatch.dylib`_dispatch_call_block_and_release + 12
>     frame #5: 0x00007fffd54fb8fc libdispatch.dylib`_dispatch_client_callout + 8
>     frame #6: 0x00007fffd55119a0 libdispatch.dylib`_dispatch_queue_serial_drain + 896
>     frame #7: 0x00007fffd5504306 libdispatch.dylib`_dispatch_queue_invoke + 1046
>     frame #8: 0x00007fffd550a020 libdispatch.dylib`_dispatch_queue_override_invoke + 369
>     frame #9: 0x00007fffd54fd6b5 libdispatch.dylib`_dispatch_root_queue_drain + 476
>     frame #10: 0x00007fffd54fd48c libdispatch.dylib`_dispatch_worker_thread3 + 99
>     frame #11: 0x00007fffd574a5a2 libsystem_pthread.dylib`_pthread_wqthread + 1299
>     frame #12: 0x00007fffd574a07d libsystem_pthread.dylib`start_wqthread + 13
>   thread #3, name = 'SGen worker'
>     frame #0: 0x00007fffd565fbf2 libsystem_kernel.dylib`__psynch_cvwait + 10
>     frame #1: 0x00007fffd574b7fa libsystem_pthread.dylib`_pthread_cond_wait + 712
>     frame #2: 0x000000010c8e0a3f LiteViewer`thread_func [inlined] mono_os_cond_wait(cond=0x000000010ca92a70, mutex=<unavailable>) at mono-os-mutex.h:173 [opt]
>     frame #3: 0x000000010c8e0a33 LiteViewer`thread_func(thread_data=0x000000010ca92a28) at sgen-thread-pool.c:108 [opt]
>     frame #4: 0x00007fffd574a93b libsystem_pthread.dylib`_pthread_body + 180
>     frame #5: 0x00007fffd574a887 libsystem_pthread.dylib`_pthread_start + 286
>     frame #6: 0x00007fffd574a08d libsystem_pthread.dylib`thread_start + 13
>   thread #4, name = 'Finalizer'
>     frame #0: 0x00007fffd5658386 libsystem_kernel.dylib`semaphore_wait_trap + 10
>     frame #1: 0x000000010c7c2025 LiteViewer`finalizer_thread [inlined] mono_os_sem_wait(flags=MONO_SEM_FLAGS_ALERTABLE) at mono-os-semaphore.h:91 [opt]
>     frame #2: 0x000000010c7c201a LiteViewer`finalizer_thread at mono-coop-semaphore.h:43 [opt]
>     frame #3: 0x000000010c7c200e LiteViewer`finalizer_thread(unused=<unavailable>) at gc.c:864 [opt]
>     frame #4: 0x000000010c872b93 LiteViewer`start_wrapper [inlined] start_wrapper_internal at threads.c:829 [opt]
>     frame #5: 0x000000010c872b13 LiteViewer`start_wrapper(data=0x0000608000261d00) at threads.c:891 [opt]
>     frame #6: 0x00007fffd574a93b libsystem_pthread.dylib`_pthread_body + 180
>     frame #7: 0x00007fffd574a887 libsystem_pthread.dylib`_pthread_start + 286
>     frame #8: 0x00007fffd574a08d libsystem_pthread.dylib`thread_start + 13
>   thread #5, name = 'Debugger agent'
>     frame #0: 0x00007fffd565fdf6 libsystem_kernel.dylib`__recvfrom + 10
>     frame #1: 0x000000010c6b77be LiteViewer`socket_transport_recv(buf="lQ", len=11) at debugger-agent.c:1148 [opt]
>     frame #2: 0x000000010c6a1cf6 LiteViewer`debugger_thread [inlined] transport_recv(len=11) at debugger-agent.c:1554 [opt]
>     frame #3: 0x000000010c6a1cd3 LiteViewer`debugger_thread(arg=<unavailable>) at debugger-agent.c:10338 [opt]
>     frame #4: 0x000000010c872b93 LiteViewer`start_wrapper [inlined] start_wrapper_internal at threads.c:829 [opt]
>     frame #5: 0x000000010c872b13 LiteViewer`start_wrapper(data=0x0000608000261980) at threads.c:891 [opt]
>     frame #6: 0x00007fffd574a93b libsystem_pthread.dylib`_pthread_body + 180
>     frame #7: 0x00007fffd574a887 libsystem_pthread.dylib`_pthread_start + 286
>     frame #8: 0x00007fffd574a08d libsystem_pthread.dylib`thread_start + 13
>   thread #6, name = 'com.apple.NSEventThread'
>     frame #0: 0x00007fffd565834a libsystem_kernel.dylib`mach_msg_trap + 10
>     frame #1: 0x00007fffd5657797 libsystem_kernel.dylib`mach_msg + 55
>     frame #2: 0x00007fffbfdac434 CoreFoundation`__CFRunLoopServiceMachPort + 212
>     frame #3: 0x00007fffbfdab8c1 CoreFoundation`__CFRunLoopRun + 1361
>     frame #4: 0x00007fffbfdab114 CoreFoundation`CFRunLoopRunSpecific + 420
>     frame #5: 0x00007fffbd9eff02 AppKit`_NSEventThread + 205
>     frame #6: 0x00007fffd574a93b libsystem_pthread.dylib`_pthread_body + 180
>     frame #7: 0x00007fffd574a887 libsystem_pthread.dylib`_pthread_start + 286
>     frame #8: 0x00007fffd574a08d libsystem_pthread.dylib`thread_start + 13
>   thread #7
>     frame #0: 0x00007fffd566044e libsystem_kernel.dylib`__workq_kernreturn + 10
>     frame #1: 0x00007fffd574a621 libsystem_pthread.dylib`_pthread_wqthread + 1426
>     frame #2: 0x00007fffd574a07d libsystem_pthread.dylib`start_wqthread + 13
>   thread #8
>     frame #0: 0x00007fffd566044e libsystem_kernel.dylib`__workq_kernreturn + 10
>     frame #1: 0x00007fffd574a48e libsystem_pthread.dylib`_pthread_wqthread + 1023
>     frame #2: 0x00007fffd574a07d libsystem_pthread.dylib`start_wqthread + 13
> (lldb) detach

> =================================================================
> 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.
> =================================================================

> Process 38567 detached
> (lldb) quit
Comment 1 Jim Borden 2017-11-13 01:41:52 UTC
To repro this, just try to open a cblite2 database file, I will attach one to this ticket (unzip first and open the folder contained)
Comment 2 Jim Borden 2017-11-13 01:43:50 UTC
Created attachment 25658 [details]
Sample database for use with repro project
Comment 3 Zoltan Varga 2017-11-13 17:05:43 UTC
I can reproduce.
Comment 4 Zoltan Varga 2017-11-13 18:57:52 UTC
https://github.com/mono/mono/pull/5999

Thanks for the testcase.
Comment 5 Jim Borden 2017-11-14 02:03:58 UTC
I see the target milestone is set to 15.5, does that mean that Xamarin.Mac is going to bump its mono version to a version including this fix in that timeframe?  I downloaded Xamarin.Mac from GitHub and compiled it from the latest master but I don't think the submodule was updated to include this fix.  I'm trying to update the mono submodule manually but so far the crash persists.

Or is there another process I can use to try to see if this fix changes things?  I don't need a production ready build since this project is just for my own fun.
Comment 6 Zoltan Varga 2017-11-14 02:14:56 UTC
The fix is currently in the mono master/2017-10 branches.
Comment 7 Jim Borden 2017-11-14 02:23:05 UTC
Yes, I saw that.  So is my thinking correct that if I want to test this inside of a Xamarin Mac application that I should:

1. Clone xamarin-macios
2. Update the mono submodule to a commit with the fix
3. Compile with IGNORE_MONO_VERSION (to prevent false "out of date mono" warning)
4. Install to system
5. Recompile Xamarin Mac application
Comment 8 Zoltan Varga 2017-11-14 04:05:35 UTC
That should work in theory.
Comment 9 Chris Hamons 2017-11-14 18:49:48 UTC
@Jim - Yes, that should work. 

If not, feel free to poke me on https://gitter.im/xamarin/xamarin-macios and i'll help you get something built.
Comment 10 Jim Borden 2017-12-04 23:54:31 UTC
FYI This just happened in Xamarin iOS 11.4.0.214...was this fix incorporated?
Comment 11 Jim Borden 2017-12-04 23:59:40 UTC
To answer my own question...no...it is not.  When will this commit be included into Xamarin iOS?  Without it even simple things are crashing.
Comment 12 Jim Borden 2017-12-05 01:15:03 UTC
Now what's worse...Xamarin Android is also affected...
Comment 13 Brendan Zagaeski (Xamarin Team, assistant) 2017-12-07 06:09:17 UTC
## Quick status update

Thanks for the check on target milestone and version integration.  Your results are correct.  In short, the accurate target milestone for this bug at the moment is 15.6 (to line up with the branches mentioned in Comment 6).  I have updated the target milestone accordingly.
Comment 14 Brendan Zagaeski (Xamarin Team, assistant) 2017-12-07 06:13:20 UTC
I will also plan to check on a few details about this bug over the next day and update the bug report again as appropriate.
Comment 15 Jim Borden 2017-12-07 06:16:26 UTC
Thanks for the response.  In the meantime I had to downgrade the Xamarin versions.  This was easy on Mac but ridiculous on Windows...it required me to uninstall and reinstall the entirety of Visual Studio (30+ GB).  I would love it if Xamarin frameworks were as easily independently installable on Windows as they are on Mac.
Comment 16 brett 2017-12-07 18:12:55 UTC
What versions did you downgrade to?  I ran into this issue when upgrading our branch of couchbase lite.
Comment 17 Jim Borden 2017-12-07 21:24:31 UTC
See the comment on https://github.com/couchbase/couchbase-lite-net/issues/934 for which version to downgrade to.
Comment 18 Jim Borden 2017-12-07 21:24:51 UTC
For Windows, downgrade to Visual Studio 15.4.5
Comment 19 Brendan Zagaeski (Xamarin Team, assistant) 2017-12-08 00:05:08 UTC
> if Xamarin frameworks were as easily independently installable on
> Windows as they are on Mac

In case it might be of interest, there is at least one UserVoice feature request that approximately matches that request: https://xamarin.uservoice.com/forums/144858-xamarin-platform-suggestions/suggestions/19263328-allow-installing-older-versions-of-xamarin-in-visu
Comment 20 Brendan Zagaeski (Xamarin Team, assistant) 2017-12-08 05:39:14 UTC
## Version history status

Regression in mono 2017-06 branch vs. mono 2017-04 branch.  Verified fixed in the mono 2017-10 branch.

> GOOD: Xamarin.Mac mono-2017-10 (0b00cb8) (Embedded Mono: 2017-10/1d891bf) (After the fix [1])
> BAD:  Xamarin.Mac mono-2017-10 (7c23bb5) (Embedded Mono: 2017-10/dcbdec8) (Before the fix)
> BAD:  Xamarin.Mac 4.0.0.214    (c4240f3) (Embedded Mono: 2017-06/950ea65)
> GOOD: Xamarin.Mac 3.8.1.0      (124197e) (Embedded Mono: 2017-04/99b248f)
[1] https://github.com/mono/mono/commit/eade041bfdd9874f639c8a2c76781bf503b2a7c4




## Steps followed to test

1. Add http://mobile.nuget.couchbase.com/nuget/Developer/ to the NuGet package sources list in Visual Studio for Mac (as per [2]).

2. Download and open the test case from Comment 0 in Visual Studio for Mac.  (Note that the test case requires an installation of Visual Studio for Mac with both .NET Core and Xamarin.Mac.)

3. Download and unzip the sample database from Comment 2.

4. Run the Xamarin.Mac app in the Debug configuration.

5. When the app launches, click the "Open" button and open the sample database from step 3.  (Select the travel-sample.cblite2 directory.)

6. After the debugger pauses on the breakpoint, continue debugging.  In the "bad" versions, the app will now crash as described in Comment 0.


[2] https://developer.couchbase.com/documentation/mobile/2.0/guides/couchbase-lite/index.html?language=csharp




## Potential workaround

Based on my brief informal testing, it appears that a potential workaround for the original Couchbase.Lite scenario could be to change: 

```
var keys = default(FLSharedKeys*);
```

to:
```
FLSharedKeys* keys = null;
```

in https://github.com/couchbase/couchbase-lite-net/blob/ed2bafb3d7dae1157cc65cfeb9f5e9db808b4cb2/src/Couchbase.Lite/API/Database/Database.cs#L182




## Additional information

The problematic scenario is related to instantiating an `unsafe struct` and assigning it to a field.  A console C# app that references Couchbase.Lite 2.0 and simply calls `new Database("foo")` in `Main()` also hits the issue.  A couple even smaller examples are listed below.

Note that in the case of example 1, the compiler generates a field for the lambda expression.  Setting the local variable `x` to `null` outside the lambda expression (no fields involved) does not cause a problem.



### Minimized example 1

```
using System;

namespace Program
{
    class MainClass
    {
        public unsafe static void Main(string[] args)
        {
            var x = default(MyStruct*);
            ((Action)(() => x = null))();
        }
    }

    unsafe struct MyStruct
    {
    }
}
```



### Minimized example 2
```
namespace Program
{
    unsafe class MainClass
    {
        static MyStruct* myStruct;

        public unsafe static void Main(string[] args)
        {
            myStruct = default(MyStruct*);
        }
    }

    unsafe struct MyStruct
    {
    }
}
```
Comment 21 Jim Borden 2017-12-08 05:53:09 UTC
Nice analysis!  This kind of stuff is quite interesting.  So the summary is that default(PointerToUnsafeStruct) potentially causes the issue?  I could go ahead and find all the times I do that in the codebase and change them to PointerToUnsafeStruct = null to see if it helps.
Comment 22 Brendan Zagaeski (Xamarin Team, assistant) 2017-12-11 19:28:06 UTC
I think that might be correct, yes.  Partly to satisfy my own curiosity, when I get a chance I'll plan to take a closer look at where the Mono runtime functions `mono_ptr_class_get()` and `mono_fnptr_class_get()` get called and what other functions touch the `min_align` field (matching up with the pull request from Comment 4).  Off-hand it seems about right that the `*class_get()` functions would only be involved when creating a new `unsafe struct` in _managed_ code, so I think initializing to `null` would work around the problem as long as the future assignments to the field are all from native structs (which I think might be the case for this Couchbase.Lite scenario).
Comment 23 Jim Albert 2017-12-15 15:36:04 UTC
Is there any way to tell from the visual studio release notes or the about dialog what version of mono is included in the release? or another way to tell if this issue was fixed?

Visual Studio 15.5.2 was just released yesterday, but their release notes only link to bug reports on their own developer community site, and also don't list the versions of the components included in the release.

https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#15.5.2
Comment 24 Brendan Zagaeski (Xamarin Team, assistant) 2017-12-15 21:30:59 UTC
> Is there any way to tell from the visual studio release notes
For the release notes, you would want to look at the SDK release notes for Xamarin.Android [1] or Xamarin.iOS [2].  (Side note: You can find these under "Help > Xamarin" in Visual Studio in case that's handy for the future.  As I understand it, there is some planning in progress for the SDK release notes moving forward that might make them more discoverable from the context of the Visual Studio release notes.)

[1] https://developer.xamarin.com/releases/android/xamarin.android_8/xamarin.android_8.1/
[2] https://developer.xamarin.com/releases/ios/xamarin.ios_11/xamarin.ios_11.6/


> ... or the about dialog
For Xamarin.iOS, you can also find the embedded Mono version based on the about dialog in Visual Studio:

1. Take the abbreviated commit hash from the about dialog (for example "6857dfc" for the current Xamarin.iOS SDK version).

2. Find the Mono submodule version for that commit in the Xamarin.iOS open source repository:
https://github.com/xamarin/xamarin-macios/tree/6857dfc/external

(This trick doesn't quite work for Xamarin.Android right now because the Xamarin.Android team has not yet had a chance to switch their build structure to make the final productized Xamarin.Android packages from the open source repo.  So the commit hash in the about dialog for Xamarin.Android instead currently comes from a non-public parent repo that is used for the productized package build.

But you can get close.  The tip of the corresponding open source branch should be very close to the released version for non-preview versions (especially right after a release).  So for example, for the Xamarin 15.5 Release, you can look at the "d15-5" branch: https://github.com/xamarin/xamarin-android/tree/d15-5/external.)


> ... or another way
If by chance I am involved on the bug report and have commented previously about the presence or absence of the commit, I'm happy to answer again for some newer version if requested.

For this particular case, I can tell you that the commit is not yet included, and this bug's target milestone of 15.6 is still accurate.  The current versions of Mono embedded in the products for the Xamarin 15.5 Release come from the mono/2017-06 branch.  That embedded Mono branch would only change during a feature release update (from the Xamarin 15.5 Release to the Xamarin 15.6 Release for example), so this fix would only be included into a Xamarin 15.5 Service Release if it was specifically added back to the mono/2017-06 branch (and the submodule reference was updated accordingly in the Xamarin SDKs).




## Follow-up question for @Jim from Comment 23

Are you also seeing this issue by using Couchbase.Lite 2.0?  I'm curious just in very rough terms about any other libraries or users who might be using `unsafe struct` types.
Comment 25 Jim Albert 2017-12-15 22:34:23 UTC
Thanks for all of the info!  I'll update my team on the status.

Yes, we're seeing this from Couchbase.Lite 2.0 as well.  I believe the Couchbase team is also working on a fix, but I wanted to check if the 15.5.2 release had any impact and was hoping to avoid installing it first if it wasn't necessary.
Comment 26 Brendan Zagaeski (Xamarin Team, assistant) 2017-12-18 18:31:08 UTC
Sounds good.  Thanks for the additional info!