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
AsyncConsumerDataProcessor.ConsumeAsync should avoid running on threadpool #6858
Currently, we run AsyncConsumerDataProcessor.ConsumeAsync on threadpool. We should avoid that.
User test code might end up blocking all threadpool threads, causing the platform to not be able to make any further progress (could that impact the ability to capture hangdump in anyway?)
We should also run some tests with DOTNET_ThreadPool_ForceMinWorkerThreads and DOTNET_ThreadPool_ForceMaxWorkerThreads environment variables to 1. Such tests could also test for a user code that gets a threadpool thread and block it. These tests should also consider running with some of the extensions we have, e.g, trx, hangdump, etc...
A different situation to consider is if we actually end up blocking the threadpool thread we are running on, and if there is only one single threadpool thread, then we might be causing a deadlock.
On .NET Framework, we call into BlockingCollection<T>.GetConsumingEnumerable, which would block the threadpool until something is published. If the publishing also needs threadpool, we might be deadlocking.
Also worth noting: We call AsyncConsumerDataProcessor per data consumer. So, the more data consumers that are installed in the test app, the more threadpool threads we could end up blocking, at least on .NET Framework where we use BlockingCollection<T>.
Yes I'm not aware of any reports that would be caused by this. The issues are probably most likely .NET Framework only. It might be fine to run on the threadpool for .NET 8+.
It's only not very straightforward to fix. We have this loop in ConsumeAsync:
// We let the catch below to handle the graceful cancellation of the process
catch(Exceptionex)when(exis not OperationCanceledException)
{
// If we're draining before to increment the _totalPayloadProcessed we need to signal that we should throw because
// it's possible we have a race condition where the payload check at line 106 return false and the current task is not yet in a
// "faulted state".
_consumerState.SetException(ex);
// We let current task to move to fault state, checked inside CompleteAddingAsync.
throw;
}
}
finally
{
Interlocked.Increment(ref_totalPayloadProcessed);
}
}
Even if we start on a long-running thread, we could get back on a threadpool thread, depending on which thread completes the task returned by DataConsumer.ConsumeAsync.
Activity
nohwnd commentedon Nov 4, 2025
Feels like "low priority" since we did not really have anyone reporting this, do we?
Youssef1313 commentedon Nov 4, 2025
Yes I'm not aware of any reports that would be caused by this. The issues are probably most likely .NET Framework only. It might be fine to run on the threadpool for .NET 8+.
It's only not very straightforward to fix. We have this loop in
ConsumeAsync:testfx/src/Platform/Microsoft.Testing.Platform/Messages/ConsumingEnumerableConsumerDataProcessor.cs
Lines 48 to 81 in 2001ece
Even if we start on a long-running thread, we could get back on a threadpool thread, depending on which thread completes the task returned by
DataConsumer.ConsumeAsync.Youssef1313 commentedon Nov 4, 2025
Maybe what we should do here instead is finding an alternative to
BlockingCollection<T>?