Permalink
Browse files

Handle slow machines which exceed timeouts in the threadpool-exceptio…

…ns<N> tests.
  • Loading branch information...
1 parent c670654 commit 0810e8defe29239f5f4185cfbefacb740fe72ab9 @vargaz vargaz committed Aug 4, 2011
@@ -2,18 +2,27 @@
using System.Threading;
class Test {
+ static object monitor;
+
static int Main ()
{
+ monitor = new object ();
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
ThreadPool.QueueUserWorkItem ((a) => {
throw new Exception ("From the threadpoool");
});
+ lock (monitor) {
+ Monitor.Wait (monitor);
+ }
Thread.Sleep (1000);
return 1;
}
static void OnUnhandledException (object sender, UnhandledExceptionEventArgs e)
{
+ lock (monitor) {
+ Monitor.Pulse (monitor);
+ }
Environment.Exit (0);
}
}
@@ -2,14 +2,20 @@
using System.Threading;
class Test {
+ static object monitor;
static int return_value = 2;
+
static int Main ()
{
+ monitor = new object ();
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
WaitCallback wcb = new WaitCallback ((a) => {
throw new Exception ("From the threadpoool");
});
wcb.BeginInvoke (wcb, OnCBFinished, null);
+ lock (monitor) {
+ Monitor.Wait (monitor);
+ }
Thread.Sleep (1000);
return 1;
}
@@ -19,6 +25,9 @@ static void OnUnhandledException (object sender, UnhandledExceptionEventArgs e)
string str = e.ExceptionObject.ToString ();
if (str.IndexOf ("From the threadpool") != -1)
return_value = 3;
+ lock (monitor) {
+ Monitor.Pulse (monitor);
+ }
Environment.Exit (return_value);
}
@@ -2,13 +2,19 @@
using System.Threading;
class Test {
+ static object monitor;
+
static int Main ()
{
+ monitor = new object ();
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
WaitCallback wcb = new WaitCallback ((a) => {
throw new Exception ("From the threadpoool");
});
wcb.BeginInvoke (wcb, OnCBFinished, null);
+ lock (monitor) {
+ Monitor.Wait (monitor);
+ }
Thread.Sleep (1000);
return 1;
}
@@ -20,6 +26,9 @@ static void OnCBFinished (object arg)
static void OnUnhandledException (object sender, UnhandledExceptionEventArgs e)
{
+ lock (monitor) {
+ Monitor.Pulse (monitor);
+ }
Environment.Exit (0);
}
}
@@ -2,14 +2,19 @@
using System.Threading;
class Test {
+ static object monitor;
static int return_value = 2;
static int Main ()
{
+ monitor = new object ();
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
WaitCallback wcb = new WaitCallback ((a) => {
Thread.CurrentThread.Abort();
});
wcb.BeginInvoke (wcb, OnCBFinished, null);
+ lock (monitor) {
+ Monitor.Wait (monitor);
+ }
Thread.Sleep (1000);
return 1;
}
@@ -19,6 +24,9 @@ static void OnUnhandledException (object sender, UnhandledExceptionEventArgs e)
string str = e.ExceptionObject.ToString ();
if (str.IndexOf ("From the threadpool") != -1)
return_value = 3;
+ lock (monitor) {
+ Monitor.Pulse (monitor);
+ }
Environment.Exit (return_value);
}

4 comments on commit 0810e8d

Contributor

@vargaz when I run threadpool-exceptions5.exe with 4.0.9.13 I see the following and the test hangs

exception inside UnhandledException handler: Thread was being aborted

Contributor

It looks as though the string manipulation in OnUnhandledExceptionHandler is resulting in a call to System.Globalization.CultureInfo:get_current_locale_name() which is causing the exception

To test this, if I add the following to the top of main then we no longer see the exception and hang

var c = CultureInfo.InstalledUICulture;

Not a solution I imagine but it might give some insight into why we're seeing exceptions within the unhandled exception handler...

Member

@ajlennon This should be fixed with #2414. Thanks for your workaround, it pointed me in the right direction.

Contributor

@akoeplinger I'm glad it was of some use. Thanks for the fix

Please sign in to comment.