Skip to content

[RuntimeAsync] Runtime Async may not honor ExecutionContext.SuppressFlow(). #122052

Description

@VSadov

Flowing execution context when it is suppressed is observable. One purpose for suppressing could be hiding secrets, although most commonly the flow is suppressed for performance reasons.

Not reacting to suppression may result in failures like:

    System.Net.Sockets.Tests.ExecutionContextFlowTest.SocketAsyncEventArgs_ExecutionContextFlowsAcrossSendAsyncOperation(suppressContext: True, sendMode: 2) [FAIL]
      Assert.Equal() Failure: Values differ
      Expected: 0
      Actual:   42
      Stack Trace:
        /_/src/libraries/System.Net.Sockets/tests/FunctionalTests/ExecutionContextFlowTest.cs(345,0): at System.Net.Sockets.Tests.ExecutionContextFlowTest.SocketAsyncEventArgs_ExecutionContextFlowsAcrossSendAsyncOperation(Boolean suppressContext, Int32 sendMode)
        /_/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs(478,0): at System.Runtime.CompilerServices.AsyncHelpers.RuntimeAsyncTaskCore.DispatchContinuations[T,TOps](T task)
        --- End of stack trace from previous location ---
        --- End of stack trace from previous location ---
  Finished:    System.Net.Sockets.Tests

Activity

  1. added this to the 11.0.0 milestone on Nov 29, 2025
  2. self-assigned this
    on Nov 29, 2025
  3. VSadov commented on Nov 29, 2025

    @VSadov
    MemberAuthor

    I think this can be fixed by simply checking for IsFlowSuppressed in RestoreContextsOnSuspension and not capturing exec context, but need to be sure.

    Possible Fix: 2982687

    == Edit:
    RestoreContextsOnSuspension may be used for synchronous restore (i.e. before calling into notifier). CaptureExecutionContext could be a more appropriate place.

  4. added a commit that references this issue on Dec 11, 2025
    4913280
  5. davidwrighton commented on Jan 6, 2026

    @davidwrighton
    Member

    This is not fixed if DOTNET_JitOptimizeAwait is set to 0.

  6. VSadov commented on Jan 7, 2026

    @VSadov
    MemberAuthor

    This is not fixed if DOTNET_JitOptimizeAwait is set to 0.

    The unoptimized path uses the actual awaiter, thus we typically do not have compat issues there.
    When there is no Task/awaiter - that is when we get into all kind of trouble and need to simulate what awaiter would do.

    It is possible though that somehow we still have an issue or something regressed.

    How did it reproduce? Just via running some existing tests with set DOTNET_JitOptimizeAwait=0 ?

  7. VSadov commented on Jul 3, 2026

    @VSadov
    MemberAuthor

    we should run tests with set DOTNET_JitOptimizeAwait=0 and see what happens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

  • Status
    No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions