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
Ensure reasonable behavior on exceptions during suspension #121465
Priority:1Work that is critical for the release, but we could probably ship withoutarea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIruntime-async
@stephentoub For task-based async what is our stance on OOM happening when the state machine is boxed? It seems like it is basically not recoverable for the user, but I don't think we fail fast or anything like that, right?
@stephentoub For task-based async what is our stance on OOM happening when the state machine is boxed? It seems like it is basically not recoverable for the user, but I don't think we fail fast or anything like that, right?
On some of these code paths, in particular where user code could possibly run, we catch any unexpected exceptions and queue them to be re-thrown on a thread pool thread, such that when they then go unhandled, by default the process will crash. I don't believe we have such catches for system code, though, and thus it wouldn't handle all cases where allocating the state machine box OOM'd.
So for async1 I think what will happen in this case is:
The callee will have boxed successfully and already will have been queued as a continuation onto something else
The caller throws and will be marked as finishing synchronously with an exception. That exception will propagate to callers that will also then finish synchronously and not try to box.
For runtime async, at the point where we throw on failure to allocate we won't yet have called OnCompleted for the leaf. So we will just finish the remaining callers synchronously, leaving TLS state indicating that we were supposed to call OnCompleted.
We cannot reliably call OnCompleted at this point, because at this point we may not even have allocated a RuntimeAsyncTask representing that this is an async operation, so we don't even have a callback delegate to pass it. If the OOM somehow gets handled by the callers the async methods that succeeded in allocating continuations will be lost, i.e. they will never have their resumption invoked.
That might not be completely unreasonable behavior. Thoughts? There are other options, like we try to preallocate some RuntimeAsyncTask instances that can be used in the situation. Or, we try to immediately resume the async methods that succeeded in allocating continuations, simulating that actually the OOM happened when the leaf tried to allocate its continuation. Then we would have to handle all the possibilities of that, e.g. another suspension or another exception thrown.
Priority:1Work that is critical for the release, but we could probably ship withoutarea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIruntime-async
Activity
dotnet-policy-service commentedon Nov 8, 2025
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
jakobbotsch commentedon Nov 26, 2025
@stephentoub For task-based async what is our stance on OOM happening when the state machine is boxed? It seems like it is basically not recoverable for the user, but I don't think we fail fast or anything like that, right?
stephentoub commentedon Nov 27, 2025
On some of these code paths, in particular where user code could possibly run, we catch any unexpected exceptions and queue them to be re-thrown on a thread pool thread, such that when they then go unhandled, by default the process will crash. I don't believe we have such catches for system code, though, and thus it wouldn't handle all cases where allocating the state machine box OOM'd.
jakobbotsch commentedon Jul 15, 2026
So for async1 I think what will happen in this case is:
For runtime async, at the point where we throw on failure to allocate we won't yet have called
OnCompletedfor the leaf. So we will just finish the remaining callers synchronously, leaving TLS state indicating that we were supposed to callOnCompleted.We cannot reliably call
OnCompletedat this point, because at this point we may not even have allocated aRuntimeAsyncTaskrepresenting that this is an async operation, so we don't even have a callback delegate to pass it. If the OOM somehow gets handled by the callers the async methods that succeeded in allocating continuations will be lost, i.e. they will never have their resumption invoked.That might not be completely unreasonable behavior. Thoughts? There are other options, like we try to preallocate some
RuntimeAsyncTaskinstances that can be used in the situation. Or, we try to immediately resume the async methods that succeeded in allocating continuations, simulating that actually the OOM happened when the leaf tried to allocate its continuation. Then we would have to handle all the possibilities of that, e.g. another suspension or another exception thrown.cc @VSadov @jkotas @davidwrighton
jakobbotsch commentedon Aug 14, 2026
I think we can decide further what the behavior should be in .NET 12.