Bug 49274 - cctor + ThreadAbortException random failures
Summary: cctor + ThreadAbortException random failures
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-12-08 06:32 UTC by Zoltan Varga
Modified: 2017-10-06 23:30 UTC (History)
3 users (show)

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

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 Zoltan Varga 2016-12-08 06:32:12 UTC
This can be reproduced by the following testcase:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
using System;
using System.Reflection;
using System.Threading;

public class Tests
{
	public static void Main (String[] args) {
		Timer t = new Timer (delegate (object state) {}, null, 10000, 1);
	}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


Unhandled Exception:
System.TypeInitializationException: The type initializer for 'System.Collections.Generic.List`1' threw an exception. ---> System.Threading.ThreadAbortException
   --- End of inner exception stack trace ---
  at System.Threading.Timer+Scheduler.SchedulerThread () [0x0000f] in <dbd8d83e40d84547af35267a08f893f8>:0 



Applying the following patch makes it happen more often:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c
index 6721ba5..3c8d5ce 100644
--- a/mono/metadata/threads.c
+++ b/mono/metadata/threads.c
@@ -854,6 +854,7 @@ static guint32 WINAPI start_wrapper_internal(StartInfo *start_info, gsize *stack
 
                g_assert (start_delegate != NULL);
 
+               mono_thread_info_sleep (3, NULL);
                /* we may want to handle the exception here. See comment below on unhandled exceptions */
                args [0] = (gpointer) start_delegate_arg;
                mono_runtime_delegate_invoke_checked (start_delegate, args, &error);
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

What happens is that by the time 		mono_threads_begin_abort_protected_block ();
is called in mono_runtime_class_init (), there is already a tae executing in async_abort_critical ().