dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.26k stars 4.73k forks source link

WASM: NullReferenceException in exception stack trace retrieval #40307

Closed akoeplinger closed 4 years ago

akoeplinger commented 4 years ago

This shows up like this in tests:

System.NullReferenceException : Object reference not set to an instance of an object.
    at System.Diagnostics.StackFrame..ctor(MonoStackFrame monoStackFrame, Boolean needFileInfo)
    at System.Diagnostics.StackTrace.InitializeForException(Exception e, Int32 skipFrames, Boolean needFileInfo)
    at System.Diagnostics.StackTrace..ctor(Exception e, Boolean fNeedFileInfo)
    at System.Exception.GetStackTrace(Boolean needFileInfo)
    at System.Exception.get_StackTrace()
    at System.Exception.ToString()
    ...

or like this:

System.NullReferenceException: Object reference not set to an instance of an object.
    at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
    at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
    at System.Exception.CaptureDispatchState()
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo..ctor(Exception exception)
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(Exception source)
    ...

The common thing is that both of these call the StackTrace.get_trace() icall.

I was only able to reproduce this one time after a few hours of running System.Linq.Tests.Parallel tests locally and we hit this only ten times on all PRs in the last ten days so it seems quite rare.

/cc @vargaz

v-haren commented 4 years ago

failed again in job: runtime 20200804.72

failed test: System.Xml.Tests.TCNamespaceHandling.NS_Handling_19a(utils: XmlWriterUtils { Async = False, WriterType = UTF8Writer }, nsHandling: OmitDuplicates, prefix: \"xmlns\", name: \"lang\", isAttr: False)

Error message

System.NullReferenceException : Object reference not set to an instance of an object.

Stack trace
   at System.Diagnostics.StackFrame..ctor(MonoStackFrame monoStackFrame, Boolean needFileInfo)
   at System.Diagnostics.StackTrace.InitializeForException(Exception e, Int32 skipFrames, Boolean needFileInfo)
   at System.Diagnostics.StackTrace..ctor(Exception e, Boolean fNeedFileInfo)
   at System.Exception.GetStackTrace(Boolean needFileInfo)
   at System.Exception.get_StackTrace()
   at System.Exception.ToString()
   at OLEDB.Test.ModuleCore.CError.Write(Object value)
   at OLEDB.Test.ModuleCore.CError.WriteLine(Object value)
   at System.Xml.Tests.TCNamespaceHandling.NS_Handling_19a(XmlWriterUtils utils, NamespaceHandling nsHandling, String prefix, String name, Boolean isAttr)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
SamMonoRT commented 4 years ago

@vargaz @BrzVlad - can this be closed now that https://github.com/dotnet/runtime/pull/40384 is merged ?

BrzVlad commented 4 years ago

While it's hard to be 100% sure, let's close this as I remember testing the fix for a few hours without failures.

akoeplinger commented 4 years ago

I ran a Kusto query on test failures and didn't find any matches after the fix was merged đź‘Ť