Skip to content

[BUG] Fatal error 0xC0000005 on instrumentation #1753

Open
@rootix

Description

@rootix

Describe the bug
We use coverlet.collector together with dotnet test command. On our CI-Environemnt (Windows Agent on Azure DevOps OnPrem) we get periodically failures while the tests are running. We have over 20 Test projects and everytime it is a different project that has the error. Sometimes it runs trough without any issue.

I searched for the stacktrace (below) and found some vstest issues which pointed to change from 17.13.0 to 17.14.preview (microsoft/vstest#2952 (comment)) and another post which mentioned 17.10.0 as the one where the issues does not occur with vstest (microsoft/vstest#10402). But i think the issue is not vstest itself but Coverlet which produces the initial error which causes then the vstest process to fail. I experienced the issue with 17.13.0 and 17.14.preview but not with 17.10.0 after 2 pipeline runs. But i got on both other versions runs without an issue, so i have low confidence that this is the fix.

To Reproduce
I cannot provide the projects that have this issue and don't know how to make a minimal reproduction for this issue.

Expected behavior
There is no error with coverlet enabled.

Actual behavior
The stacktrace that we get is:

   Fatal error. 0xC0000005
      at Mono.Cecil.Pdb.ISymUnmanagedWriter2.Close()
      at Mono.Cecil.Pdb.SymWriter.Close()
      at Mono.Cecil.Pdb.NativePdbWriter.Write()
      at Mono.Cecil.ModuleWriter.Write(Mono.Cecil.ModuleDefinition, Mono.Disposable`1<System.IO.Stream>, Mono.Cecil.WriterParameters)
      at Mono.Cecil.ModuleWriter.WriteModule(Mono.Cecil.ModuleDefinition, Mono.Disposable`1<System.IO.Stream>, Mono.Cecil.WriterParameters)
      at Mono.Cecil.ModuleDefinition.Write(System.IO.Stream, Mono.Cecil.WriterParameters)
      at Coverlet.Core.Instrumentation.Instrumenter.InstrumentModule()
      at Coverlet.Core.Instrumentation.Instrumenter.Instrument()
      at Coverlet.Core.Coverage.PrepareModules()
      at Coverlet.Collector.DataCollection.CoverageWrapper.PrepareModules(Coverlet.Core.Coverage)
      at Coverlet.Collector.DataCollection.CoverageManager.InstrumentModules()
      at Coverlet.Collector.DataCollection.CoverletCoverageCollector.OnSessionStart(System.Object, Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection.SessionStartEventArgs)
      at System.RuntimeMethodHandle.InvokeMethod(System.Object, Void**, System.Signature, Boolean)
      at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(System.Object, System.Span`1<System.Object>, System.Reflection.BindingFlags)
      at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
      at System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
      at System.Delegate.DynamicInvokeImpl(System.Object[])
      at Microsoft.VisualStudio.TestPlatform.Utilities.MulticastDelegateUtilities.SafeInvoke(System.Delegate, System.Object, System.Object, System.String)
      at Microsoft.VisualStudio.TestPlatform.Common.DataCollector.TestPlatformDataCollectionEvents.RaiseEvent(Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection.DataCollectionEventArgs)
      at Microsoft.VisualStudio.TestPlatform.Common.DataCollector.DataCollectionManager.SessionStarted(Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection.SessionStartEventArgs)
      at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection.DataCollectionRequestHandler.HandleBeforeTestRunStart(Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Message)
      at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection.DataCollectionRequestHandler.ProcessRequests()
      at Microsoft.VisualStudio.TestPlatform.DataCollector.DataCollectorMain.Run(System.String[])
      at Microsoft.VisualStudio.TestPlatform.DataCollector.Program.Main(System.String[])
   
   System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
    ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.
      at System.Net.Sockets.NetworkStream.Read(Span`1 buffer)
      --- End of inner exception stack trace ---
      at System.Net.Sockets.NetworkStream.Read(Span`1 buffer)
      at System.Net.Sockets.NetworkStream.ReadByte()
      at System.IO.BinaryReader.Read7BitEncodedInt()
      at System.IO.BinaryReader.ReadString()
      at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.SocketCommunicationManager.ReceiveRawMessage() in /_/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs:line 321
      at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection.DataCollectionRequestSender.SendBeforeTestRunStartAndGetResult(String settingsXml, IEnumerable`1 sources, Boolean isTelemetryOptedIn, ITestMessageEventHandler runEventsHandler) in /_/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestSender.cs:line 119
      at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.ProxyDataCollectionManager.<>c__DisplayClass21_0.<BeforeTestRunStart>b__0() in /_/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs:line 197
      at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.ProxyDataCollectionManager.InvokeDataCollectionServiceAction(Action action, ITestMessageEventHandler runEventsHandler) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs:line 288
   System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..
    ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.
      at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 count)
      --- End of inner exception stack trace ---
      at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 count)
      at System.IO.BufferedStream.Flush()
      at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.SocketCommunicationManager.WriteAndFlushToChannel(String rawMessage) in /_/src/Microsoft.TestPlatform.CommunicationUtilities/SocketCommunicationManager.cs:line 413
      at Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection.DataCollectionRequestSender.SendAfterTestRunEndAndGetResult(ITestMessageEventHandler runEventsHandler, Boolean isCancelled) in /_/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestSender.cs:line 155
      at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.ProxyDataCollectionManager.<>c__DisplayClass20_0.<AfterTestRunEnd>b__0() in /_/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs:line 155

The tests are executed with the following command (per project since we split unit and integration test projects):

dotnet.exe test <path-to-csproj>.csproj --configuration Release --no-build --no-restore --verbosity minimal --collect "XPlat Code Coverage" --settings <path-to>\coverlet.runsettings --logger nunit;LogFilePath=<path-to>/<project>.TestResults.xml

Configuration (please complete the following information):
Please provide more information on your .NET configuration:
* Which coverlet package and version was used? -> 6.0.4
* Which version of .NET is the code running on? 9.0.200
* What OS and version, and what distro if applicable? Azure DevOps Agent Runner (Windows)
* What is the architecture (x64, x86, ARM, ARM64)? -> x64
* Do you know whether it is specific to that configuration? -> No

Additional context

Content of our coverlet.runsettings:

<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
  <DataCollectionRunSettings>
    <DataCollectors>
      <DataCollector friendlyName="XPlat code coverage">
        <Configuration>
          <Format>cobertura</Format>
          <Exclude>[Namespace.*.Test.*]*, [Namespace.Shared.Test]*,[*]*.DbAccess.Migrations.*</Exclude>
        </Configuration>
      </DataCollector>
    </DataCollectors>
  </DataCollectionRunSettings>
</RunSettings>

Metadata

Metadata

Assignees

No one assigned

    Labels

    untriagedTo be investigated

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions