diff options
author | Alexander Köplinger <alex.koeplinger@outlook.com> | 2017-11-08 16:44:30 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-08 16:44:30 +0300 |
commit | a45569fe370ec50c81942ca45eac6ac93edc515c (patch) | |
tree | c488ddb5646898fb22b1367d4944cec31d73e66b /mcs/class/System | |
parent | 198481639f16608328fff11a57f990a12003e27c (diff) |
[System] Fix NullReferenceException in Win32EventLog (#5949)
This occasionally happens:
```
System.NullReferenceException : Object reference not set to an instance of an object
at System.Diagnostics.Win32EventLog.NotifyEventThread (System.Threading.ManualResetEvent resetEvent) [0x00001] in D:\j\workspace\w\mcs\class\System\System.Diagnostics\Win32EventLog.cs:739
at System.Diagnostics.Win32EventLog.<EnableNotification>b__44_0 () [0x00000] in D:\j\workspace\w\mcs\class\System\System.Diagnostics\Win32EventLog.cs:729
at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00014] in D:\j\workspace\w\mcs\class\referencesource\mscorlib\system\threading\thread.cs:68
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in D:\j\workspace\w\mcs\class\referencesource\mscorlib\system\threading\executioncontext.cs:957
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in D:\j\workspace\w\mcs\class\referencesource\mscorlib\system\threading\executioncontext.cs:904
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x0002b] in D:\j\workspace\w\mcs\class\referencesource\mscorlib\system\threading\executioncontext.cs:893
at System.Threading.ThreadHelper.ThreadStart () [0x00008] in D:\j\workspace\w\mcs\class\referencesource\mscorlib\system\threading\thread.cs:105
```
We'll get it because there's a race as the lamdba capturing
_notifyResetEvent in EnableNotification() is outside of the
_eventLock so _notifyResetEvent can be null by the time it is called.
We need to check for that case in NotifyEventThread().
Diffstat (limited to 'mcs/class/System')
-rw-r--r-- | mcs/class/System/System.Diagnostics/Win32EventLog.cs | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/mcs/class/System/System.Diagnostics/Win32EventLog.cs b/mcs/class/System/System.Diagnostics/Win32EventLog.cs index 29d6e55b443..ac986545548 100644 --- a/mcs/class/System/System.Diagnostics/Win32EventLog.cs +++ b/mcs/class/System/System.Diagnostics/Win32EventLog.cs @@ -734,6 +734,9 @@ namespace System.Diagnostics private void NotifyEventThread (ManualResetEvent resetEvent) { + if (resetEvent == null) + return; + while (true) { try { resetEvent.WaitOne (); |