dotnet / dotnet/aspnetcore

Remove blocking APIs in asp.net core integration tests code

Open
#43,353 16 comments 2 reactions 0 assignees View on GitHub
area-networking bug help wanted
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

Even on our very powerful Macbook pros, when we are running one of our integration test projects that has hundreds of tests, many of which use WebApplicationFactory we often get into deadlocks.

We set xunit to use unlimited amount of threads (-1), we have overridden a bunch of xunit stuff to implement a semaphore to limit the number of concurrent tests.
And yet, often we get into deadlocks after the ~600 tests completed mark.
After verifying we have no sync-over-async, we found this beauty in asp.net core code itself...
![image](https://user-images.githubusercontent.com/6141009/185249861-e8d6ac6c-84d0-4d47-8358-715643671ca0.png)

https://github.com/dotnet/aspnetcore/blob/main/src/Hosting/TestHost/src/TestServer.cs#L101
As well as this: https://github.com/dotnet/runtime/blob/2be87c9c976c0cd21b66ea12ae406a559aacaac0/src/libraries/Microsoft.Extensions.Hosting.Abstractions/src/HostingAbstractionsHostExtensions.cs#L19

later on when we managed to reproduce the deadlock (after a very high number of attempts).
![image](https://user-images.githubusercontent.com/6141009/185250465-4eb78fc6-842a-4434-a5c5-afddd3825160.png)

Bear in mind, xUnit which is by far the number 1 testing framework for .NET Core has SynchronizationContexts, even if [this issue](https://github.com/xunit/xunit/issues/2573) would be solved, there is still the `MaxConcurrencySyncContext` which I can only assume would still be used by default.

Can we please remove the sync over async anti pattern from our beloved framework?

Best,
Doron

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.