Bug 51653

Summary: mono_thread_info_wait_one_handle ignored alertable argument
Product: [Mono] Runtime Reporter: Rodrigo Kumpera <kumpera>
Component: GeneralAssignee: Ludovic Henry <ludovic>
Severity: normal CC: mono-bugs+mono, mono-bugs+runtime
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

Description Rodrigo Kumpera 2017-01-20 00:44:23 UTC
The runtime needs non-alertable wait during the shutdown in gc.c when waiting the finalizer thread.

This can be reproduced by calling Environment.Exit from a catch handler that just got a TAE.
Comment 1 Rodrigo Kumpera 2017-01-20 00:47:29 UTC
I'm adding a workaround for this in ves_icall_System_Environment_Exit. It should be removed once this is fixed.
Comment 2 Ludovic Henry 2017-02-07 21:34:33 UTC
@kumpera how do I reproduce this bug? I have made the os-event alertable, but I need to check if that fixed it. See https://github.com/mono/mono/pull/4341
Comment 3 Rodrigo Kumpera 2017-02-07 22:00:32 UTC
Ok, verifying this is going to be hard without explicitly modifying the runtime. I'm aware of only the gc cleanup code using mono_thread_info_wait_one_handle in non-alertable mode.

To use my scenario, you can use mono/tests/abort-cctor.cs.

You'll make the Environment.Exit (6) crash.
To do that, you need to break self aborts to respect static cctors.

This is a simple hack. In threads.c: mono_thread_set_interruption_requested, change the force_interrupt variable to be always false and enjoy the crash.
Comment 4 Ludovic Henry 2017-02-08 16:15:18 UTC
@kumpera I am confused: should it crash when setting the force_interrupt to FALSE, or should it not?

What I am witnessing is an assertion at https://github.com/mono/mono/blob/master/mono/metadata/gc.c#L1067 as it returns MONO_THREAD_INFO_WAIT_RET_ALERTED because of the self interrupt at https://github.com/mono/mono/blob/master/mono/metadata/threads.c#L4919
Comment 5 Rodrigo Kumpera 2017-02-09 06:57:16 UTC
Oh! My bad!

If you change gc.c:1067 to use a non-aletable wait it should not crash with your PR.
Comment 6 Ludovic Henry 2017-02-09 16:20:49 UTC
I updated gc.c:1067 to be non-alertable, and I don't see the crash anymore. Marking as fixed.
Comment 7 Ludovic Henry 2017-02-09 16:21:09 UTC
This is fixed with https://github.com/mono/mono/pull/4347