Skip to content

Code Coverage collection Fails with "System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.." #154

Open

Description

I am running unit tests locally on my workstation and started seeing some errors occurring with my tests. The tests all seem to pass just fine but when it seems to be collecting Code Coverage data I get a lot of the following errors

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
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.ProxyDataCollectionManager.InvokeDataCollectionServiceAction(Action action, ITestMessageEventHandler runEventsHandler) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/ProxyDataCollectionManager.cs:line 288

If I remove code coverage (essentially the --collect parameter) my tests work and complete as expected. This is using dotnet 9.0.102

dotnet test "./Framework/Framework.sln" -c Release -bl:./"Framework.Tests.binlog"  --no-build --no-restore --results-directory ./TestResults --collect:"Code Coverage;Format=cobertura"

Activity

  1. fhnaseer commented on Jan 31, 2025

    @fhnaseer
    Member

    Can you run collect logs and share these? dotnet test ... --diag log.dotnet.txt

  2. blemke1971 commented on Jan 31, 2025

    @blemke1971
    Author

    Here is the single log.dotnet.txt file. There were about 151 other log.dotnet.host.*txt files created too but I have not uploaded those.

    log.dotnet.zip

  3. fhnaseer commented on Jan 31, 2025

    @fhnaseer
    Member

    There will be datacollector.txt (something similar), can you please share that one as well?

  4. blemke1971 commented on Jan 31, 2025

    @blemke1971
    Author

    There are about 47 or so projects in this solution so there are a bunch of log.dotnet.datacollector.#DATETIMESTAMP#.txt files. I have zipped them up and attached them.

    dotnetcollector.zip

  5. fhnaseer commented on Feb 3, 2025

    @fhnaseer
    Member

    Do you have native projects in your solution? Can you use vstest.console.exe to run tests instead of dotnet test?

  6. blemke1971 commented on Feb 3, 2025

    @blemke1971
    Author

    There is nothing specific. It was working a few weeks ago just fine. I do not know if there was an update applied to the dotnet system that broke this. I am in process of trying to run some of this with vstest console to see if it works. I just do not understand why all of a sudden it stopped.

  7. blemke1971 commented on Feb 3, 2025

    @blemke1971
    Author

    But just to confirm yes the vstest.console.exe does work

  8. fhnaseer commented on Feb 4, 2025

    @fhnaseer
    Member

    Can you please share Microsoft.NET.Test.Sdk version in your test project? Was there any change in this that triggered this issue? If you are using any preview version, I would recommend using latest stable version in all of your test projects.

  9. blemke1971 commented on Feb 4, 2025

    @blemke1971
    Author

    Here are the current versions for the MS test values

    <PackageVersion Include="Microsoft.Data.Tools.UnitTest" Version="17.8.103.1" />
    <PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
    <PackageVersion Include="MSTest.TestAdapter" Version="3.7.3" />
    <PackageVersion Include="MSTest.TestFramework" Version="3.7.3" />
    
  10. fhnaseer commented on Feb 4, 2025

    @fhnaseer
    Member

    I see that you are using latest version (which was released a week ago) => https://www.nuget.org/packages/MSTest.TestAdapter
    17.13.0 version of Microsoft.NET.Test.Sdk will be released soon. This issue might be fixed in that release.

  11. blemke1971 commented on Feb 10, 2025

    @blemke1971
    Author

    fhnaseer So I noticed that 17.13.0 got released and the issue still seems to persist. I also tested the 17.14.0-preview-25107-01 version. That preview version also still fails when collecting code coverage. Both SDK's work just fine in testing if we do not collect code coverage. So it seems to be just related to code coverage.

  12. fhnaseer commented on Feb 10, 2025

    @fhnaseer
    Member

    Is it possible to provide a minimum repro for this?

    Also, can you please try with the following settings?

    <?xml version="1.0" encoding="utf-8"?>
    <RunSettings>
        <DataCollectionRunSettings>
            <DataCollectors>
                <DataCollector friendlyName="Code Coverage"
                    uri="datacollector://Microsoft/CodeCoverage/2.0"
                    assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
                    <Configuration>
                        <CodeCoverage>
                            <EnableDynamicNativeInstrumentation>False</EnableDynamicNativeInstrumentation>
                            <EnableStaticNativeInstrumentation>False</EnableStaticNativeInstrumentation>
                        </CodeCoverage>
                    </Configuration>
                </DataCollector>
            </DataCollectors>
        </DataCollectionRunSettings>
    </RunSettings>
    
  13. blemke1971 commented on Feb 10, 2025

    @blemke1971
    Author

    I am not sure i can provide any repo for this. I know that drastically limits our ability to troubleshoot but its private IP. And I do not know how to sanitize this but I will see if I can figure out a way.

    as for the second part with those two options set to false. The same errors still happen. In fact they seem to happen faster.

  14. fhnaseer commented on Feb 12, 2025

    @fhnaseer
    Member

    I see that you are running tests on the whole solution. Maybe you can try to run tests on individual projects, and we can find which project is causing this issue. Also, you can create a ticket on https://developercommunity.visualstudio.com/VisualStudio which can be used to share things in more secure way.

  15. blemke1971 commented on Feb 19, 2025

    @blemke1971
    Author

    So I tried running on individual projects and no single project is causing the issue. It only seems to take effect when I run it seems to be random on which project it fails on. Sometimes its right away and sometimes it waits until near the end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions