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.
I'm adding a workaround for this in ves_icall_System_Environment_Exit. It should be removed once this is fixed.
@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
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.
@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
Oh! My bad!
If you change gc.c:1067 to use a non-aletable wait it should not crash with your PR.
I updated gc.c:1067 to be non-alertable, and I don't see the crash anymore. Marking as fixed.
This is fixed with https://github.com/mono/mono/pull/4347