Microsoft.AspNetCore.Mvc.Testing : The request was aborted or the pipeline has finished on TeamCity
See original GitHub issueDescribe the bug
Our Integration Suite on TeamCity keeps on failing randomly but runs fine locally from Visual Studio and command line as well.
To Reproduce
Steps to reproduce the behavior:
- Using this version of ASP.NET Core ‘2.1.1’
- Run tests on TeamCity
Expected behavior
Assert errors but no errors from TestHost
Screenshots
Stack trace from TeamCity:
Failed Agoda.Ycs.Gateway.IntegrationTests.GetCakesEndpointTest.CakesEndpointTest(url: "/api/Cakes/1")
Error Message:
System.IO.IOException : The request was aborted or the pipeline has finished
Stack Trace:
at Microsoft.AspNetCore.TestHost.ResponseStream.CheckNotComplete()
at Microsoft.AspNetCore.TestHost.ResponseStream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
at Microsoft.AspNetCore.WebUtilities.HttpResponseStreamWriter.FlushInternalAsync(Boolean flushEncoder)
at Microsoft.AspNetCore.Mvc.Formatters.JsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
at Agoda.Ycs.Gateway.Api.Middlewares.MeasurementsLoggingMiddleware.Invoke(HttpContext context, IOptionsSnapshot`1 adpMessagingClientSettings)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIIndexMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.TestHost.HttpContextBuilder.<>c__DisplayClass10_0.<<SendAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.TestHost.ClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Mvc.Testing.Handlers.CookieContainerHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Mvc.Testing.Handlers.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
at Agoda.Ycs.Gateway.IntegrationTests.GetEndpointTestBase`1.EndpointsReturnSuccessAndCorrectContentType(String url) in /opt/buildagent/work/69f9ec429751afcd/tests/Agoda.Ycs.Gateway.IntegrationTests/GetEndpointTestBase.cs:line 16
at Agoda.Ycs.Gateway.IntegrationTests.GetCakesEndpointTest.CakesEndpointTest(String url) in /opt/buildagent/work/69f9ec429751afcd/tests/Agoda.Ycs.Gateway.IntegrationTests/GetCakesEndpointTest.cs:line 15
Additional context
- Teamcity agents are running Linux, version 3.10.0-862.3.3.el7.x86_64
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Microsoft.AspNetCore.Mvc.Testing : The request was ...
Describe the bug. Our Integration Suite on TeamCity keeps on failing randomly but runs fine locally from Visual Studio and command line as...
Read more >NET 6 E2E tests with test server fail on TeamCity CI, but ...
NET 6 from .NET Framework, I wanted to run E2E cypress tests on the web application. My process is that I actually run...
Read more >Continuous Integration with TeamCity and Docker
In this article, we are going to learn a bit about more advanced features of TeamCity, how to build Docker images and run...
Read more >How To Resolve Issue Of Test Project Not Running The ...
I was upgrading the .NET Core 3.1 project to .NET 6 and faced issues running test cases in my test projects. I had...
Read more >Team City – Curious case of failed tests but passed build
As part of the build pipeline, I had usual build steps to Build the solution, Run Unit Tests, Run Integration Tests, and then...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I found this issue from similar symptoms and wanted to add an extra bit of information that helped me diagnose, for the next person who sees this.
Something in the request was taking too long, which was triggering the HttpClient’s default timeout of 100 seconds. AspNetCore Cancellation Tokens don’t cause an immediate failure, but instead will trigger when you try to write your response, giving the error above “The request was aborted or the pipeline has finished” at that point.
Adding internal timeouts to the internal Http calls inside your service helps to find the cause of the slow requests, and trigger the failure where it is slow rather than after it is slow.
Otherwise we basically had the same issue as @Ibrahim-Islam (slow upstream responses)
Increasing default HTTPClient timeout for me fixed it.
client.Timeout = System.TimeSpan.FromMinutes(3);