You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
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
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
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.
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.
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.
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.
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.
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.
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.
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
Activity
fhnaseer commentedon Jan 31, 2025
Can you run collect logs and share these?
dotnet test ... --diag log.dotnet.txtblemke1971 commentedon Jan 31, 2025
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
fhnaseer commentedon Jan 31, 2025
There will be datacollector.txt (something similar), can you please share that one as well?
blemke1971 commentedon Jan 31, 2025
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
fhnaseer commentedon Feb 3, 2025
Do you have native projects in your solution? Can you use vstest.console.exe to run tests instead of dotnet test?
blemke1971 commentedon Feb 3, 2025
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.
blemke1971 commentedon Feb 3, 2025
But just to confirm yes the vstest.console.exe does work
fhnaseer commentedon Feb 4, 2025
Can you please share
Microsoft.NET.Test.Sdkversion 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.blemke1971 commentedon Feb 4, 2025
Here are the current versions for the MS test values
fhnaseer commentedon Feb 4, 2025
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.
blemke1971 commentedon Feb 10, 2025
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.
fhnaseer commentedon Feb 10, 2025
Is it possible to provide a minimum repro for this?
Also, can you please try with the following settings?
blemke1971 commentedon Feb 10, 2025
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.
fhnaseer commentedon Feb 12, 2025
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.
blemke1971 commentedon Feb 19, 2025
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