This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 52429 - Shutdown hang then crash in Finalizer thread
Summary: Shutdown hang then crash in Finalizer thread
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: GC (show other bugs)
Version: Trunk
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
: 44355 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-02-10 01:17 UTC by Ludovic Henry
Modified: 2017-05-18 11:00 UTC (History)
4 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Ludovic Henry 2017-02-10 01:17:13 UTC
Observed behaviour:
The runtime waits for the finalizer to run for 40 seconds, and then crash when trying to stop the finalizer thread with the following assertion: "* Assertion at gc.c:1058, condition `ret != MONO_THREAD_INFO_WAIT_RET_TIMEOUT' not met"

Desired behaviour:
The runtime waits for the finalizer to run for 40 seconds, and then shutdown the runtime properly.

To reproduce run the following:

> using System;
> using System.Threading;
> using System.Runtime.InteropServices;
> 
> class Driver
> {
> 	static class Bar
> 	{
> 		static Bar ()
> 		{
> 			Console.WriteLine ("Bar.cctor");
> 			Thread.Sleep (1000);
> 		}
> 
> 		static public void Init()
> 		{
> 		}
> 	}
> 
> 	class Foo
> 	{
> 		~Foo ()
> 		{
> 			Console.WriteLine ("Foo.dtor");
> 			Bar.Init();
> 		}
> 	}
> 
> 	public static int Main ()
> 	{
> 		Thread t = new Thread(() => {
> 			new Foo();
> 			Console.WriteLine ("Exit");
> 			Environment.Exit (0);
> 		});
> 
> 		t.Start ();
> 
> 		Bar.Init ();
> 
> 		t.Join ();
> 
> 		Thread.Sleep(1000);
> 		Console.WriteLine("Main returns");
> 		return 1;
> 	}
> }

The observed output is:

> Bar.cctor
> Exit
> set interrupt unhappy, as it's only putting a deferred req 0
> Foo.dtor
> * Assertion at gc.c:1058, condition `ret != MONO_THREAD_INFO_WAIT_RET_TIMEOUT' not met
> 
> Stacktrace:
> 
>   at <unknown> <0xffffffff>
>   at (wrapper managed-to-native) System.Environment.Exit (int) [0x00000] in <9ca5a5fee2f24747a317c5c0dd1ceb86>:0
>   at Driver.<Main>m__0 () [0x00010] in <90236cc5d8924940b31d44b3c3ee3539>:0
>   at System.Threading.ThreadHelper.ThreadStart_Context (object) [0x00014] in <9ca5a5fee2f24747a317c5c0dd1ceb86>:0
>   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) [0x00071] in <9ca5a5fee2f24747a317c5c0dd1ceb86>:0
>   at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) [0x00000] in <9ca5a5fee2f24747a317c5c0dd1ceb86>:0
>   at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object) [0x0002b] in <9ca5a5fee2f24747a317c5c0dd1ceb86>:0
>   at System.Threading.ThreadHelper.ThreadStart () [0x00008] in <9ca5a5fee2f24747a317c5c0dd1ceb86>:0
>   at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) [0x0004d] in <9ca5a5fee2f24747a317c5c0dd1ceb86>:0
> 
> Native stacktrace:
> 
> 	0   mono                                0x0000000108951ee2 mono_handle_native_crash + 370
> 	1   mono                                0x0000000108a3d580 sigabrt_signal_handler + 160
> 	2   libsystem_platform.dylib            0x00007fff9107552a _sigtramp + 26
> 	3   mono                                0x0000000108d886b5 my_charset + 4205
> 	4   libsystem_c.dylib                   0x00007fff942806df abort + 129
> 	5   mono                                0x0000000108c6dd93 mono_log_write_logfile + 419
> 	6   mono                                0x0000000108c63d2c structured_log_adapter + 60
> 	7   mono                                0x0000000108c9261d monoeg_g_logv + 109
> 	8   mono                                0x0000000108c92a04 monoeg_assertion_message + 356
> 	9   mono                                0x0000000108b7c524 mono_gc_cleanup + 420
> 	10  mono                                0x0000000108b70696 mono_runtime_cleanup + 22
> 	11  mono                                0x0000000108848ad8 mini_cleanup + 72
> 	12  mono                                0x0000000108b70713 mono_runtime_quit + 51
> 	13  mono                                0x0000000108aa1bb0 ves_icall_System_Environment_Exit + 48
> 	14  ???                                 0x00000001092cc907 0x0 + 4448897287
> 	15  ???                                 0x000000010920b441 0x0 + 4448105537
> 	16  ???                                 0x000000010920b377 0x0 + 4448105335
> 	17  ???                                 0x000000010920ae32 0x0 + 4448103986
> 	18  ???                                 0x000000010920a979 0x0 + 4448102777
> 	19  ???                                 0x000000010920a8c8 0x0 + 4448102600
> 	20  ???                                 0x000000010920a79d 0x0 + 4448102301
> 	21  ???                                 0x000000010920a601 0x0 + 4448101889
> 	22  mono                                0x00000001088466ed mono_jit_runtime_invoke + 2493
> 	23  mono                                0x0000000108b88496 do_runtime_invoke + 182
> 	24  mono                                0x0000000108b82157 mono_runtime_invoke_checked + 103
> 	25  mono                                0x0000000108b8a5ac mono_runtime_delegate_try_invoke + 188
> 	26  mono                                0x0000000108b8a5f2 mono_runtime_delegate_invoke_checked + 50
> 	27  mono                                0x0000000108b3bf4b start_wrapper_internal + 763
> 	28  mono                                0x0000000108b3bb39 start_wrapper + 25
> 	29  mono                                0x0000000108c81c37 inner_start_thread + 215
> 	30  libsystem_pthread.dylib             0x00007fff93de299d _pthread_body + 131
> 	31  libsystem_pthread.dylib             0x00007fff93de291a _pthread_body + 0
> 	32  libsystem_pthread.dylib             0x00007fff93de0351 thread_start + 13
> 
> Debug info from gdb:
> 
> (lldb) command source -s 0 '/tmp/mono-gdb-commands.DOb0eO'
> Executing commands in '/tmp/mono-gdb-commands.DOb0eO'.
> (lldb) process attach --pid 59233
> Process 59233 stopped
> * thread #1: tid = 0xcf88dc, 0x00000001092cc980, name = 'tid_50f', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
>     frame #0: 0x00000001092cc980
> ->  0x1092cc980: pushq  %rbp
>     0x1092cc981: movq   %rsp, %rbp
>     0x1092cc984: subq   $0x50, %rsp
>     0x1092cc988: movq   %rsp, -0x30(%rbp)
> 
> Executable module set to "/Users/ludovic/Xamarin/mono/mono/mini/mono".
> Architecture set to: x86_64h-apple-macosx.
> (lldb) thread list
> Process 59233 stopped
> * thread #1: tid = 0xcf88dc, 0x00000001092cc980, name = 'tid_50f', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
>   thread #2: tid = 0xcf88dd, 0x00007fff8c86ddb6 libsystem_kernel.dylib`__psynch_cvwait + 10, name = 'SGen worker'
>   thread #3: tid = 0xcf88de, 0x00007fff8c86dde6 libsystem_kernel.dylib`__psynch_mutexwait + 10, name = 'Finalizer'
>   thread #4: tid = 0xcf88e0, 0x00007fff8c86eefa libsystem_kernel.dylib`kevent_qos + 10, queue = 'com.apple.libdispatch-manager'
>   thread #5: tid = 0xcf88e1, 0x00007fff8c86e582 libsystem_kernel.dylib`__wait4 + 10, name = 'tid_2003'
> (lldb) thread backtrace all
> * thread #1: tid = 0xcf88dc, 0x00000001092cc980, name = 'tid_50f', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
>   * frame #0: 0x00000001092cc980
>     frame #1: 0x000000010920a52d
>     frame #2: 0x000000010920a6bf
>     frame #3: 0x00000001088466ed mono`mono_jit_runtime_invoke(method=0x00007fa1ba7037a0, obj=0x0000000000000000, params=0x0000000000000000, exc=0x00007fff573ce658, error=0x00007fff573ceb40) + 2493 at mini-runtime.c:2530
>     frame #4: 0x0000000108b88496 mono`do_runtime_invoke(method=0x00007fa1ba7037a0, obj=0x0000000000000000, params=0x0000000000000000, exc=0x00007fff573ce658, error=0x00007fff573ceb40) + 182 at object.c:2851
>     frame #5: 0x0000000108b831a8 mono`mono_runtime_try_invoke(method=0x00007fa1ba7037a0, obj=0x0000000000000000, params=0x0000000000000000, exc=0x00007fff573ce658, error=0x00007fff573ceb40) + 184 at object.c:2962
>     frame #6: 0x0000000108b829c8 mono`mono_runtime_class_init_full(vtable=0x00007fa1bc003ba0, error=0x00007fff573ceb40) + 1032 at object.c:474
>     frame #7: 0x000000010883ef21 mono`mono_jit_compile_method_inner(method=0x00007fa1ba703748, target_domain=0x00007fa1ba603990, opt=370239999, error=0x00007fff573ceb40) + 4097 at mini.c:4357
>     frame #8: 0x000000010884388a mono`mono_jit_compile_method_with_opt(method=0x00007fa1ba703748, opt=370239999, error=0x00007fff573ceb40) + 1546 at mini-runtime.c:1885
>     frame #9: 0x000000010884326b mono`mono_jit_compile_method(method=0x00007fa1ba703748, error=0x00007fff573ceb40) + 59 at mini-runtime.c:1929
>     frame #10: 0x0000000108956d02 mono`common_call_trampoline(regs=0x00007fff573cec28, code="I\x8b�A�?, m=0x00007fa1ba703748, vt=0x0000000000000000, vtable_slot=0x0000000000000000, error=0x00007fff573ceb40) + 2770 at mini-trampolines.c:699
>     frame #11: 0x00000001089561fb mono`mono_magic_trampoline(regs=0x00007fff573cec28, code="I\x8b�A�?, arg=0x00007fa1ba703748, tramp="�J�H7p\xba\xa1\x7f") + 107 at mini-trampolines.c:829
>     frame #12: 0x000000010915a39e
>     frame #13: 0x000000010920923f
>     frame #14: 0x00000001092093d6
>     frame #15: 0x00000001088466ed mono`mono_jit_runtime_invoke(method=0x00007fa1ba604fc8, obj=0x0000000000000000, params=0x00007fff573cf370, exc=0x0000000000000000, error=0x00007fff573cf430) + 2493 at mini-runtime.c:2530
>     frame #16: 0x0000000108b88496 mono`do_runtime_invoke(method=0x00007fa1ba604fc8, obj=0x0000000000000000, params=0x00007fff573cf370, exc=0x0000000000000000, error=0x00007fff573cf430) + 182 at object.c:2851
>     frame #17: 0x0000000108b82157 mono`mono_runtime_invoke_checked(method=0x00007fa1ba604fc8, obj=0x0000000000000000, params=0x00007fff573cf370, error=0x00007fff573cf430) + 103 at object.c:3009
>     frame #18: 0x0000000108b8c486 mono`do_exec_main_checked(method=0x00007fa1ba604fc8, args=0x00000001094003e8, error=0x00007fff573cf430) + 182 at object.c:4671
>     frame #19: 0x0000000108b8aed2 mono`mono_runtime_exec_main_checked(method=0x00007fa1ba604fc8, args=0x00000001094003e8, error=0x00007fff573cf430) + 66 at object.c:4772
>     frame #20: 0x0000000108b8af25 mono`mono_runtime_run_main_checked(method=0x00007fa1ba604fc8, argc=1, argv=0x00007fff573cf890, error=0x00007fff573cf430) + 69 at object.c:4221
>     frame #21: 0x0000000108908773 mono`mono_jit_exec(domain=0x00007fa1ba603990, assembly=0x00007fa1ba7010d0, argc=1, argv=0x00007fff573cf890) + 403 at driver.c:1029
>     frame #22: 0x000000010890c66a mono`main_thread_handler(user_data=0x00007fff573cf7d0) + 538 at driver.c:1098
>     frame #23: 0x000000010890aeb3 mono`mono_main(argc=2, argv=0x00007fff573cf888) + 8467 at driver.c:2168
>     frame #24: 0x000000010883159e mono`mono_main_with_options(argc=2, argv=0x00007fff573cf888) + 46 at main.c:45
>     frame #25: 0x0000000108830cdd mono`main(argc=2, argv=0x00007fff573cf888) + 77 at main.c:338
>     frame #26: 0x00007fff87b8a5ad libdyld.dylib`start + 1
>     frame #27: 0x00007fff87b8a5ad libdyld.dylib`start + 1
> 
>   thread #2: tid = 0xcf88dd, 0x00007fff8c86ddb6 libsystem_kernel.dylib`__psynch_cvwait + 10, name = 'SGen worker'
>     frame #0: 0x00007fff8c86ddb6 libsystem_kernel.dylib`__psynch_cvwait + 10
>     frame #1: 0x00007fff93de3728 libsystem_pthread.dylib`_pthread_cond_wait + 767
>     frame #2: 0x0000000108c5fa2d mono`mono_os_cond_wait(cond=0x0000000108d85ec8, mutex=0x0000000108d85e88) + 29 at mono-os-mutex.h:146
>     frame #3: 0x0000000108c5f646 mono`thread_func(thread_data=0x00000001091fd108) + 166 at sgen-thread-pool.c:129
>     frame #4: 0x00007fff93de299d libsystem_pthread.dylib`_pthread_body + 131
>     frame #5: 0x00007fff93de291a libsystem_pthread.dylib`_pthread_start + 168
>     frame #6: 0x00007fff93de0351 libsystem_pthread.dylib`thread_start + 13
> 
>   thread #3: tid = 0xcf88de, 0x00007fff8c86dde6 libsystem_kernel.dylib`__psynch_mutexwait + 10, name = 'Finalizer'
>     frame #0: 0x00007fff8c86dde6 libsystem_kernel.dylib`__psynch_mutexwait + 10
>     frame #1: 0x00007fff93de2e4a libsystem_pthread.dylib`_pthread_mutex_lock_wait + 89
>     frame #2: 0x00007fff93de05f5 libsystem_pthread.dylib`_pthread_mutex_lock_slow + 300
>     frame #3: 0x0000000108b93495 mono`mono_os_mutex_lock(mutex=0x00007fa1ba502fe0) + 21 at mono-os-mutex.h:94
>     frame #4: 0x0000000108b933be mono`mono_coop_mutex_lock(mutex=0x00007fa1ba502fe0) + 62 at mono-coop-mutex.h:53
>     frame #5: 0x0000000108b830e9 mono`mono_type_init_lock(lock=0x00007fa1ba502fd0) + 25 at object.c:182
>     frame #6: 0x0000000108b82c42 mono`mono_runtime_class_init_full(vtable=0x00007fa1bc003ba0, error=0x00007000002837d0) + 1666 at object.c:531
>     frame #7: 0x000000010884362e mono`mono_jit_compile_method_with_opt(method=0x00007fa1ba703748, opt=370239999, error=0x00007000002837d0) + 942 at mini-runtime.c:1828
>     frame #8: 0x000000010884326b mono`mono_jit_compile_method(method=0x00007fa1ba703748, error=0x00007000002837d0) + 59 at mini-runtime.c:1929
>     frame #9: 0x0000000108956d02 mono`common_call_trampoline(regs=0x00007000002838b8, code="H\x83�\x06", m=0x00007fa1ba703748, vt=0x0000000000000000, vtable_slot=0x0000000000000000, error=0x00007000002837d0) + 2770 at mini-trampolines.c:699
>     frame #10: 0x00000001089561fb mono`mono_magic_trampoline(regs=0x00007000002838b8, code="H\x83�\x06", arg=0x00007fa1ba703748, tramp="�J�H7p\xba\xa1\x7f") + 107 at mini-trampolines.c:829
>     frame #11: 0x000000010915a39e
>     frame #12: 0x00000001092ccb90
>     frame #13: 0x00000001092ccac5
>     frame #14: 0x0000000108b7b326 mono`mono_gc_run_finalize(obj=0x00000001092641e0, data=0x0000000000000000) + 1510 at gc.c:331
>     frame #15: 0x0000000108bd0419 mono`sgen_client_run_finalize(obj=0x00000001092641e0) + 25 at sgen-mono.c:519
>     frame #16: 0x0000000108bed113 mono`sgen_gc_invoke_finalizers + 323 at sgen-gc.c:2523
>     frame #17: 0x0000000108bd0429 mono`mono_gc_invoke_finalizers + 9 at sgen-mono.c:525
>     frame #18: 0x0000000108b7d79d mono`finalize_domain_objects + 141 at gc.c:843
>     frame #19: 0x0000000108b7d5ed mono`finalizer_thread(unused=0x0000000000000000) + 317 at gc.c:919
>     frame #20: 0x0000000108b3becd mono`start_wrapper_internal(start_info=0x0000000000000000, stack_ptr=0x0000700000283e90) + 637 at threads.c:835
>     frame #21: 0x0000000108b3bb39 mono`start_wrapper(data=0x00007fa1ba6360a0) + 25 at threads.c:887
>     frame #22: 0x0000000108c81c37 mono`inner_start_thread(data=0x00007fa1ba6360e0) + 215 at mono-threads.c:1165
>     frame #23: 0x00007fff93de299d libsystem_pthread.dylib`_pthread_body + 131
>     frame #24: 0x00007fff93de291a libsystem_pthread.dylib`_pthread_start + 168
>     frame #25: 0x00007fff93de0351 libsystem_pthread.dylib`thread_start + 13
> 
>   thread #4: tid = 0xcf88e0, 0x00007fff8c86eefa libsystem_kernel.dylib`kevent_qos + 10, queue = 'com.apple.libdispatch-manager'
>     frame #0: 0x00007fff8c86eefa libsystem_kernel.dylib`kevent_qos + 10
>     frame #1: 0x00007fff942bc165 libdispatch.dylib`_dispatch_mgr_invoke + 216
>     frame #2: 0x00007fff942bbdcd libdispatch.dylib`_dispatch_mgr_thread + 52
> 
>   thread #5: tid = 0xcf88e1, 0x00007fff8c86e582 libsystem_kernel.dylib`__wait4 + 10, name = 'tid_2003'
>     frame #0: 0x00007fff8c86e582 libsystem_kernel.dylib`__wait4 + 10
>     frame #1: 0x0000000108951ffe mono`mono_handle_native_crash(signal="SIGABRT", ctx=0x000070000051c0f0, info=0x000070000051c088) + 654 at mini-exceptions.c:2567
>     frame #2: 0x0000000108a3d580 mono`sigabrt_signal_handler(_dummy=6, _info=0x000070000051c088, context=0x000070000051c0f0) + 160 at mini-posix.c:208
>     frame #3: 0x00007fff9107552a libsystem_platform.dylib`_sigtramp + 26
>     frame #4: 0x00007fff8c86df07 libsystem_kernel.dylib`__pthread_kill + 11
>     frame #5: 0x00007fff93de54ec libsystem_pthread.dylib`pthread_kill + 90
>     frame #6: 0x00007fff942806df libsystem_c.dylib`abort + 129
>     frame #7: 0x0000000108c6dd93 mono`mono_log_write_logfile(log_domain=0x0000000000000000, level=G_LOG_LEVEL_ERROR, hdr=0, message="* Assertion at gc.c:1058, condition `ret != MONO_THREAD_INFO_WAIT_RET_TIMEOUT' not met\n") + 419 at mono-log-common.c:137
>     frame #8: 0x0000000108c63d2c mono`structured_log_adapter(log_domain=0x0000000000000000, log_level=G_LOG_LEVEL_ERROR, message="* Assertion at gc.c:1058, condition `ret != MONO_THREAD_INFO_WAIT_RET_TIMEOUT' not met\n", user_data=0x0000000000000000) + 60 at mono-logger.c:430
>     frame #9: 0x0000000108c9261d mono`monoeg_g_logv(log_domain=0x0000000000000000, log_level=G_LOG_LEVEL_ERROR, format="* Assertion at %s:%d, condition `%s' not met\n", args=0x000070000051c520) + 109 at goutput.c:115
>     frame #10: 0x0000000108c92a04 mono`monoeg_assertion_message(format="* Assertion at %s:%d, condition `%s' not met\n") + 356 at goutput.c:135
>     frame #11: 0x0000000108b7c524 mono`mono_gc_cleanup + 420 at gc.c:1058
>     frame #12: 0x0000000108b70696 mono`mono_runtime_cleanup(domain=0x00007fa1ba603990) + 22 at appdomain.c:423
>     frame #13: 0x0000000108848ad8 mono`mini_cleanup(domain=0x00007fa1ba603990) + 72 at mini-runtime.c:4106
>     frame #14: 0x0000000108b70713 mono`mono_runtime_quit + 51 at appdomain.c:449
>     frame #15: 0x0000000108aa1bb0 mono`ves_icall_System_Environment_Exit(result=0) + 48 at icall.c:6652
>     frame #16: 0x00000001092cc907
>     frame #17: 0x000000010920b441
>     frame #18: 0x000000010920b377
>     frame #19: 0x000000010920ae32
>     frame #20: 0x000000010920a979
>     frame #21: 0x000000010920a8c8
>     frame #22: 0x000000010920a79d
>     frame #23: 0x000000010920a601
>     frame #24: 0x00000001088466ed mono`mono_jit_runtime_invoke(method=0x00007fa1bc007928, obj=0x0000000109400698, params=0x000070000051ce70, exc=0x0000000000000000, error=0x000070000051cdf0) + 2493 at mini-runtime.c:2530
>     frame #25: 0x0000000108b88496 mono`do_runtime_invoke(method=0x00007fa1bc007928, obj=0x0000000109400698, params=0x000070000051ce70, exc=0x0000000000000000, error=0x000070000051cdf0) + 182 at object.c:2851
>     frame #26: 0x0000000108b82157 mono`mono_runtime_invoke_checked(method=0x00007fa1bc007928, obj=0x0000000109400698, params=0x000070000051ce70, error=0x000070000051cdf0) + 103 at object.c:3009
>     frame #27: 0x0000000108b8a5ac mono`mono_runtime_delegate_try_invoke(delegate=0x0000000109400698, params=0x000070000051ce70, exc=0x0000000000000000, error=0x000070000051cdf0) + 188 at object.c:3954
>     frame #28: 0x0000000108b8a5f2 mono`mono_runtime_delegate_invoke_checked(delegate=0x0000000109400698, params=0x000070000051ce70, error=0x000070000051cdf0) + 50 at object.c:3975
>     frame #29: 0x0000000108b3bf4b mono`start_wrapper_internal(start_info=0x0000000000000000, stack_ptr=0x000070000051ce90) + 763 at threads.c:843
>     frame #30: 0x0000000108b3bb39 mono`start_wrapper(data=0x00007fa1ba502dc0) + 25 at threads.c:887
>     frame #31: 0x0000000108c81c37 mono`inner_start_thread(data=0x00007fa1ba501810) + 215 at mono-threads.c:1165
>     frame #32: 0x00007fff93de299d libsystem_pthread.dylib`_pthread_body + 131
>     frame #33: 0x00007fff93de291a libsystem_pthread.dylib`_pthread_start + 168
>     frame #34: 0x00007fff93de0351 libsystem_pthread.dylib`thread_start + 13
> (lldb) detach
> Process 59233 detached
> (lldb) (lldb) quit
> 
> =================================================================
> 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.
> =================================================================
> 
> [3]    59233 abort      MONO_DEBUG=disable_omit_fp MONO_PATH=mcs/class/lib/net_4_x mono/mini/mono

What we can see from the stacktrace is that:
 - thread 1 is calling the cctor for vtable = 0x00007fa1bc003ba0, and is suspended by mono_thread_suspend_all_other_threads
 - thread 3 (the finalizer thread) is waiting for the cctor for vtable = 0x00007fa1bc003ba0 to finish running (waiting on thread 1)
 - thread 5 is shutting down the runtime (it's the one to call mono_thread_suspend_all_other_threads), and is waiting for thread 3 to finish running.
Comment 1 Zoltan Varga 2017-02-10 03:46:41 UTC
The reason we assert is there is no good solution here. We couldn't abort the finalizer, so managed code is still running, so if we continue with the shutdown, the finalizer might access freed runtime structures, leading to a random crash.
Comment 2 Ludovic Henry 2017-02-10 03:56:31 UTC
Couldn't we fix mono_runtime_class_init_full so the wait at https://github.com/mono/mono/blob/master/mono/metadata/object.c#L533 would check if the thread is being interrupted? I wonder what is the behaviour on .NET in this case.
Comment 3 Zoltan Varga 2017-02-10 06:12:13 UTC
The runtime actually keeps a list of class inits for each thread, calling mono_release_type_locks () will release the locks, allowing other threads to proceed. So we might want to call this for the threads which got suspended if we know we are never going to resume them.
Comment 4 Ludovic Henry 2017-02-10 16:44:29 UTC
This is dangerous, as per the pthread_mutex_unlock, "Calling pthread_mutex_unlock() with a mutex that the calling thread does not hold will result in undefined behavior.".
Right now it's safe to call from mono_thread_internal_detach, because that's only called for the current thread, but calling it from mono_thread_suspend_all_other_threads could result in the above undefined behaviour.
Comment 5 Ludovic Henry 2017-02-10 16:45:03 UTC
Also, I have a potential fix at https://github.com/mono/mono/pull/4363
Comment 6 Zoltan Varga 2017-02-10 17:04:00 UTC
https://github.com/mono/mono/pull/4361 fixes that so we no longer hold the lock while running the cctor, so calling release_type_locks () should be safe after that.
Comment 7 Lluis Sanchez 2017-05-18 11:00:15 UTC
*** Bug 44355 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.