New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Opting out of AsyncTestSyncContext #2573
Comments
@bradwilson sorry for the rude ping. Thanks in advance! |
You can deadlock the max concurrency context, which you already have a way to opt out of. Looking at the code, I cannot see how you could deadlock the async void context itself, though it does delegate to the context that is wraps (so if you're using a context which could be deadlocked, like one of the STA/UI thread extensions, that's what you're deadlocking, and it has nothing to do with the async void context). If you can reliably deadlock the async void context by itself (meaning, no other contexts, including the max concurrency context), please provide a repro project. The v3 bypass of the async void context has everything to do with performance and nothing to do with potential deadlocks.
This is not going to happen. Supporting
You can send a PR if you wish, but I have not promised there will be any more v2 releases, so you may be stuck using a MyGet-based package to get this feature for an indefinite period of time. |
This will not be fixed for v2. For v3, we only use the xunit/src/xunit.v3.core/Sdk/v3/Runners/TestInvoker.cs Lines 143 to 148 in e138f20
As such, I consider this issue resolved. |
With the release of TimeProvider in .NET 8, asynchronous operations involving time can now be processed synchronously. However, the insertion of this SynchronizationContext inadvertently leads to the use of ThreadPool, making it difficult to monitor the processes. I am working on a custom implementation of Reactive Extensions, and this behavior is very inconvenient when writing tests for complex async/await code. It's uncertain when version 3 will be released and become widespread, so I would like it to be introduced in version 2 before moving to version 3. |
Available for v2 in |
@bradwilson thanks! If I got the commit right, it's not opt-out, it's opt-in, meaning you'll get the sync context if you choose to use async void. |
It's really a matter of perspective, and whether you're accustomed to using |
FYI, this was a breaking change for CoreWCF as we have tests which depended on a non-null sync context to be set (we're validating whether we propagate it through to service call dispatch based on a behavior setting). Using the class name |
@mconnew It's unfortunate that we caused this bug, but depending on our (internal implementation detail) sync context instead of providing your own isn't really our fault.
Our release notes are pretty shallow, and we did call out the exact class in question (this is the third item in the release notes for 2.7.0): It's unfortunately impossible for me to have both anticipated that you were taking this dependency, and then how you would search to find the problem. I believe I provided as much information as most people would reasonably expect. 🤷🏼 |
Note that based on feedback from several users across several issues, this feature is being rolled back in 2.8.0, alongside the release of a new parallelism algorithm. At the same time, we have removed support for |
Hi All,
Everyone today's under the impression we are done with deadlocks because of SynchronizationContexts since they were removed in ASP.NET Core.
Problem is, the same code that works perfectly in development, staging and production is causing very weird problems and even deadlocks when run inside xunit tests.
This is because xunit added 2 SynchronizationContexts:
async void
testsWhile the former can easily be opted-out, with
MaxParallelThreads=-1
, withAsyncTestSyncContext
since it's being used very deep inside the framework in https://github.com/xunit/xunit/blob/v2/src/xunit.execution/Sdk/Frameworks/Runners/TestInvoker.cs#L238 it seems like you simply cannot opt-out unless you override a half of the framework.I noticed this is fixed with v3, where we only get AsyncTestSyncContext if the test method is in fact
async void
: https://github.com/xunit/xunit/blob/main/src/xunit.v3.core/Sdk/v3/Runners/TestInvoker.cs#L143Personally, I would throw an exception for async void, aligning xunit with .NET's other test frameworks that do not support
async void
(I honestly see no advantage of havingasync void
, probably a typo and can be fixed in a second or with a linter but many many disadvantages).Can we please add a reasonable way of opting-out of
AsyncTestSyncContext
in the production V2 branch?If investing a lot of time in it is not desirable since it's already fixed in V3, we can very easily just look at an environment variable in
TestInvoker
.Bear in mind:
Best,
Doron Grinzaig
The text was updated successfully, but these errors were encountered: