vstest: The active test run was aborted. Reason: Test host process crashed
Description
For a defect reproducable from the vstest command line, describe the issue you’ve observed.
Steps to reproduce
-
git clone https://github.com/xuzhg/WebApi.git
git checkout -b RoutingBaseForNEtCore30 origin/RoutingBaseForNEtCore30
-
dotnet --version
-
run the following command (please replace the following Folder):
dotnet test [YOURLocalClonedFolder]\test\E2ETest\Microsoft.Test.E2E.AspNet.OData\Build.AspNetCore3x\Microsoft.Test.E2E.AspNetCore3x.OData.csproj --logger trx --results-directory C:\BuildAgent\_work\_temp --configuration release --no-build -v diag
-
result:
Expected behavior
Shall pass all test cases running
Actual behavior
Crash with the error message:
<RunInfos>
<RunInfo computerName="ODataBuild50" outcome="Error" timestamp="2019-12-02T20:25:22.4166882+00:00">
<Text>The active test run was aborted. Reason: Test host process crashed : Unhandled exception. Unhandled exception. System.Threading.Tasks.TaskCanceledException: The operation was canceled.
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
at Microsoft.Test.E2E.AspNet.OData.QueryComposition.SecurityTests.TestDosAttack(String filter) in C:\BuildAgent\_work\1\s\test\E2ETest\Microsoft.Test.E2E.AspNet.OData\QueryComposition\SecurityTests.cs:line 85
at Microsoft.Test.E2E.AspNet.OData.QueryComposition.SecurityTests.<>c__DisplayClass9_0.<<TestDosAttackWithMultipleThreads>b__0>d.MoveNext() in C:\BuildAgent\_work\1\s\test\E2ETest\Microsoft.Test.E2E.AspNet.OData\QueryComposition\SecurityTests.cs:line 95
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_1(Object state)
at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
System.Threading.Tasks.TaskCanceledException: The operation was canceled.
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
at Microsoft.Test.E2E.AspNet.OData.QueryComposition.SecurityTests.TestDosAttack(String filter) in C:\BuildAgent\_work\1\s\test\E2ETest\Microsoft.Test.E2E.AspNet.OData\QueryComposition\SecurityTests.cs:line 85
at Microsoft.Test.E2E.AspNet.OData.QueryComposition.SecurityTests.<>c__DisplayClass9_0.<<TestDosAttackWithMultipleThreads>b__0>d.MoveNext() in C:\BuildAgent\_work\1\s\test\E2ETest\Microsoft.Test.E2E.AspNet.OData\QueryComposition\SecurityTests.cs:line 95
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_1(Object state)
at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
</Text>
</RunInfo>
</RunInfos>
Environment
Please share additional details about the test environment.
only installed VS2019 Enterprise.
Additional Info
If i run the failure test case individually, it can pass:
as:
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 9
- Comments: 49 (3 by maintainers)
We are getting this issue from time to time on our build server, too. It’s not consistent and sometimes it works just fine. We didn’t see before when we were running core 2.2, but now see when we are running 3.1
We are using vstest indirectly (via Microsoft.NET.Test.Sdk), and I have upgraded it to 16.5.0, and yet the error persists.
Are there any other recommendations?
Okay, I now have a reproduction for the problem, and it’s thread related.
This is the error I get:
and this is the code:
I had this issue. Here is how I resolved it:
@juwens Yes, of course it breaks a PROGRAM, but we’re discussing a UNIT TEST
@dbtfsbre you can install 5.0.101 dotnet SDK, and also install ProcDump so it is available in your PATH (if you open command line and type procdump, you should see output of the procdump tool). Then you do just:
And it should create a dump for you, open that in VS and you should see where that exception is coming from. Most likely it is your code calling some method recursively and forgetting to terminate.
I have got here due to use of wrong function.
Assert.ThrowsException<MyException>(async () => await myFunction())
Fixed by replacing to async version:await Assert.ThrowsExceptionAsync<MyException>(async () => await myFunction())
Our builds have started failing with this error. Is there a way to get some decent logs out? We are using azure hosted pipelines.
We have been getting this error for months but it’s been very intermittent, so hasn’t bothered us. But over the past 2 days it has spiked hugely.
Holy moly, that was it. Thanks dude.
That is literally what I wrote above as the cause of crash in my case (https://github.com/microsoft/vstest/issues/2261#issuecomment-1034018644). @xuzhg - please search for “async void” in your code.
try
dotnet test —-blame
it will reveal the source of the issue. In our case it were unhandled exceptions inasync void
methods and more tricky: async void lambdas.I’ve been getting this same issue, but it seemingly occurs only when running a whole test project at once; if I try to test each individual test methods in their own session/run then I never encounter the problem.
I also never get a stack trace or any meaningful debug output just before the Stack overflow occurs.
This is the most I’ve been able to extract out of the test/debug output:
Running/debugging the test project seems to make no difference. I’ve never been able to get VS to even break on the Stack overflow; this is just bizarre.
Using Xunit/.NET Core 3.1.
I just got a similar problem with my application in .NET 6
Edit: I just removed some lines of code including attributes/reflection and now the test runs perfectly. I don’t know why that caused it and how to fix it. This is the line of code I removed:
@brah-mcdude - if the application/test code itself caused the crash, this should be much more obvious/different from the other scenarios presented “The active test run was aborted. Reason: Test host process crashed” <-- too generic.
@juwens Then how do you explain it works on .net 4.6? It’s a different runtime… There’s a specific problem introduced in .net core and above.
FWIW: the solution we found was actually due to OOM kills from kubernetes gitlab-runner setup. The nodes were stretching their RAM too tightly, and eventually digging showed events where k8s was killing the dotnet process.
Looked like this:
This might not be the problem or solution for everyone, but wanted to share back as it is definitely something to consider!
@nohwnd Thanks. Something went wrong when copying files to the test machine for an investigation. The test is running fine in Visual Studio using Test Explorer and during our regular Release test runs. After compiling the test again directly on the test machine, I was able to run it with dotnet test as well as vstest.console.exe.
We had the exact same issue with our build. It turned out to be misconfigured settings for code coverage. In our CodeCoverage.runsettings-file we were not properly excluding test projects from coverage.
We were seeing similar issues in VS, there was a problem with cancellation of run that produced a cancellation error and was not caught in the correct place. It resulted in the same error, but probably not the same stack. That error is kind of a catch all for all errors when the other process disconnects in the middle of an operation so it is hard to tell. I would suggest upgrading to 16.5.0 to see if that was fixes.