diff options
author | Ludovic Henry <ludovic@xamarin.com> | 2017-02-21 23:34:03 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-21 23:34:03 +0300 |
commit | 0d2d3266b7eca379ca7c91d7c59677902596eef5 (patch) | |
tree | c62c9f2ac721e8ebf9a3664d9b3208d46961bade | |
parent | 3d7713edccd14cb32da2472047fbd348be2dc8a9 (diff) |
[threadpool] Do not swallow exception in RegisterWaitForSingleObject callback (#4408)
-rw-r--r-- | mcs/class/corlib/System.Threading/RegisteredWaitHandle.cs | 21 | ||||
-rw-r--r-- | mono/tests/Makefile.am | 3 | ||||
-rw-r--r-- | mono/tests/unhandled-exception-8.cs | 24 |
3 files changed, 36 insertions, 12 deletions
diff --git a/mcs/class/corlib/System.Threading/RegisteredWaitHandle.cs b/mcs/class/corlib/System.Threading/RegisteredWaitHandle.cs index 960ecf6e7b8..3bd11264b1a 100644 --- a/mcs/class/corlib/System.Threading/RegisteredWaitHandle.cs +++ b/mcs/class/corlib/System.Threading/RegisteredWaitHandle.cs @@ -98,17 +98,16 @@ namespace System.Threading private void DoCallBack (object timedOut) { - if (_callback != null) { - try { - _callback (_state, (bool)timedOut); - } catch {} - } - - lock (this) - { - _callsInProcess--; - if (_unregistered && _callsInProcess == 0 && _finalEvent != null) - NativeEventCalls.SetEvent (_finalEvent.SafeWaitHandle); + try { + if (_callback != null) + _callback (_state, (bool)timedOut); + } finally { + lock (this) + { + _callsInProcess--; + if (_unregistered && _callsInProcess == 0 && _finalEvent != null) + NativeEventCalls.SetEvent (_finalEvent.SafeWaitHandle); + } } } diff --git a/mono/tests/Makefile.am b/mono/tests/Makefile.am index 58ca018ac9b..d809141dcf4 100644 --- a/mono/tests/Makefile.am +++ b/mono/tests/Makefile.am @@ -1763,7 +1763,8 @@ UNHANDLED_EXCEPTION_255_TESTS = \ unhandled-exception-4.exe \ unhandled-exception-5.exe \ unhandled-exception-6.exe \ - unhandled-exception-7.exe + unhandled-exception-7.exe \ + unhandled-exception-8.exe test-unhandled-exception-2: $(UNHANDLED_EXCEPTION_1_TESTS) $(UNHANDLED_EXCEPTION_255_TESTS) $(MAKE) test-unhandled-exception-2-1-with-managed-handler diff --git a/mono/tests/unhandled-exception-8.cs b/mono/tests/unhandled-exception-8.cs new file mode 100644 index 00000000000..7b4de0e97bf --- /dev/null +++ b/mono/tests/unhandled-exception-8.cs @@ -0,0 +1,24 @@ + +using System; +using System.Threading; + +class CustomException : Exception +{ +} + +class Driver +{ + /* expected exit code: 255 */ + public static void Main () + { + if (Environment.GetEnvironmentVariable ("TEST_UNHANDLED_EXCEPTION_HANDLER") != null) + AppDomain.CurrentDomain.UnhandledException += (s, e) => {}; + + ManualResetEvent mre = new ManualResetEvent(false); + + ThreadPool.RegisterWaitForSingleObject (mre, (state, timedOut) => { throw new CustomException (); }, null, -1, true); + mre.Set(); + + Thread.Sleep (5000); + } +}
\ No newline at end of file |