Skip to content

Ensure reasonable behavior on exceptions during suspension #121465

Open

Description

@jakobbotsch

There are two possible source of exceptions during suspension:

We should ensure that something reasonable happens in these cases.

Activity

  1. added
    untriaged
    on Nov 8, 2025
  2. added
    needs-area-label
    on Nov 8, 2025
  3. added
    area-CodeGen-coreclr
    and removed
    needs-area-label
    untriaged
    on Nov 8, 2025
  4. dotnet-policy-service commented on Nov 8, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  5. jakobbotsch commented on Nov 26, 2025

    @jakobbotsch
    MemberAuthor

    @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?

  6. stephentoub commented on Nov 27, 2025

    @stephentoub
    Member

    @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.

  7. added this to the 11.0.0 milestone on Apr 17, 2026
  8. added
    Priority:2
    on Jul 9, 2026
  9. jakobbotsch commented on Jul 15, 2026

    @jakobbotsch
    MemberAuthor

    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.

    cc @VSadov @jkotas @davidwrighton

  10. added
    Priority:1
    and removed
    Priority:2
    on Jul 30, 2026
  11. jakobbotsch commented on Aug 14, 2026

    @jakobbotsch
    MemberAuthor

    I think we can decide further what the behavior should be in .NET 12.

  12. modified the milestones: 11.0.0, 12.0.0 on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Priority:1area-CodeGen-coreclrruntime-async

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions