Skip to content

Test failure: Assertion failed. state is RuntimeAsyncTask<T> #125015

Closed

Description

@jkotas
  Starting:    System.Threading.Channels.Tests (parallel test collections = on [2 threads], stop on fail = off)
Process terminated.
Assertion failed.
state is RuntimeAsyncTask<T>
   at System.Runtime.CompilerServices.AsyncHelpers.RuntimeAsyncTask`1.<>c.<.cctor>b__16_1(Object state) in /_/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs:line 711
   at System.Threading.Channels.ChannelUtilities.DangerousSetOperations[TAsyncOp,TResult](TAsyncOp head, TResult result) in /_/src/libraries/System.Threading.Channels/src/System/Threading/Channels/ChannelUtilities.cs:line 245
   at System.Threading.Channels.UnboundedChannel`1.UnboundedChannelWriter.TryWrite(T item) in /_/src/libraries/System.Threading.Channels/src/System/Threading/Channels/UnboundedChannel.cs:line 281
   at System.Threading.Channels.UnboundedChannel`1.UnboundedChannelWriter.WriteAsync(T item, CancellationToken cancellationToken) in /_/src/libraries/System.Threading.Channels/src/System/Threading/Channels/UnboundedChannel.cs:line 298
   at System.Threading.Channels.Tests.ChannelTestBase.<>c__DisplayClass26_0.<ManyProducerConsumer_ConcurrentReadWrite_Success>b__1() in /_/src/libraries/System.Threading.Channels/tests/ChannelTestBase.cs:line 248
   at System.Threading.Tasks.Task`1.InnerInvoke() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task_T.cs:line 486
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs:line 279
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:line 2424
   at System.Threading.ThreadPoolWorkQueue.Dispatch() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:line 950
   at System.Threading.PortableThreadPool.WorkerThread.WorkerDoWork(PortableThreadPool threadPoolInstance) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:line 134
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:line 110
   at System.Threading.Thread.StartCallback() in /_/src/coreclr/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs:line 116
[createdump] Gathering state for process 34 dotnet

Build Information

Build: https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=1314345
Build error leg or test failing: System.Threading.Channels.Tests.WorkItemExecution
Pull request: #124725

Error Message

Fill the error message using step by step known issues guidance.

{
  "ErrorMessage": "state is RuntimeAsyncTask<T>",
  "ErrorPattern": "",
  "BuildRetry": false,
  "ExcludeConsoleLog": false
}

Known issue validation

Build: 🔎 https://dev.azure.com/dnceng-public/public/_build/results?buildId=1314345
Error message validated: [state is RuntimeAsyncTask<T>]
Result validation: ✅ Known issue matched with the provided build.
Validation performed at: 2/28/2026 8:10:46 PM UTC

Report

Build Definition Test Pull Request
1356861 dotnet/runtime System.Threading.Channels.Tests.WorkItemExecution
1356722 dotnet/runtime System.Threading.Channels.Tests.WorkItemExecution #125900
1356463 dotnet/runtime System.Threading.Channels.Tests.WorkItemExecution #126231
1352252 dotnet/runtime System.Threading.Channels.Tests.WorkItemExecution #126091
1343605 dotnet/runtime System.Threading.Channels.Tests.WorkItemExecution #125759
1340863 dotnet/runtime System.Threading.Channels.Tests.WorkItemExecution #125436
1335001 dotnet/runtime System.Threading.Channels.Tests.WorkItemExecution #124920
1328950 dotnet/runtime System.Threading.Channels.Tests.WorkItemExecution #125211
1324436 dotnet/runtime System.Threading.Channels.Tests.WorkItemExecution #125282
1318669 dotnet/runtime System.Threading.Channels.Tests.WorkItemExecution #123819

Summary

24-Hour Hit Count 7-Day Hit Count 1-Month Count
0 4 10

Activity

  1. added
    blocking-clean-ci
    Known Build Error
    on Feb 28, 2026
  2. added
    untriaged
    on Feb 28, 2026
  3. added and removed
    untriaged
    Known Build Error
    on Feb 28, 2026
  4. dotnet-policy-service commented on Feb 28, 2026

    @dotnet-policy-service
    Contributor

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

  5. dotnet-policy-service commented on Feb 28, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-threading-tasks
    See info in area-owners.md if you want to be subscribed.

  6. added
    untriaged
    on Feb 28, 2026
  7. jakobbotsch commented on Mar 2, 2026

    @jakobbotsch
    Member

    The code looks quite innocent:

    private static readonly Action<object?> s_runContinuationAction = static state =>
    {
    Debug.Assert(state is RuntimeAsyncTask<T>);
    ((RuntimeAsyncTask<T>)state).DispatchContinuations();
    };

    vtsNotifier.OnCompleted(s_runContinuationAction, this, configFlags);

    Either we are breaking some invariants or this is some kind of a race in UnboundedChannel and how it calls continuations.

  8. jakobbotsch commented on Mar 2, 2026

    @jakobbotsch
    Member

    @stephentoub Before I dig deeper here or try to come up with a smaller repro, would this be a possible symptom of us calling OnCompleted multiple times perhaps?

  9. jakobbotsch commented on Mar 2, 2026

    @jakobbotsch
    Member

    Copilot points at a missing barrier here:

    if (ec is null)
    {
    Action<object?> c = _continuation!;
    _continuation = s_completedSentinel;
    object? state = _continuationState;
    _continuationState = null;
    c(state);
    }

    Been trying to come up with a smaller repro, but so far no luck.

  10. JulieLeeMSFT commented on Mar 3, 2026

    @JulieLeeMSFT
    Member

    Failed in: runtime-coreclr libraries-jitstress 20260224.1

    Failed tests:

    net11.0-windows-Release-arm64-jitstress2-Windows.11.Arm64.Open
        - System.Threading.Channels.Tests
    

    Error message:

      Starting:    System.Threading.Channels.Tests (parallel test collections = on [2 threads], stop on fail = off)
        System.Threading.Channels.Tests.StressTests.CanceledReads [SKIP]
          Condition(s) not met: "IsStressModeEnabled"
        System.Threading.Channels.Tests.StressTests.ReadWriteVariations [SKIP]
          Condition(s) not met: "IsStressModeEnabled"
    Process terminated.
    Assertion failed.
    state is RuntimeAsyncTask<T>
    

    Stack Trace

       at System.Runtime.CompilerServices.AsyncHelpers.RuntimeAsyncTask`1.<>c.<.cctor>b__16_1(Object state) in /_/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs:line 720
       at System.Threading.Channels.ChannelUtilities.DangerousSetOperations[TAsyncOp,TResult](TAsyncOp head, TResult result) in /_/src/libraries/System.Threading.Channels/src/System/Threading/Channels/ChannelUtilities.cs:line 245
       at System.Threading.Channels.UnboundedChannel`1.UnboundedChannelWriter.TryWrite(T item) in /_/src/libraries/System.Threading.Channels/src/System/Threading/Channels/UnboundedChannel.cs:line 281
       at System.Threading.Channels.Tests.ChannelTestBase.<>c__DisplayClass26_0.<ManyProducerConsumer_ConcurrentReadWrite_Success>b__1()
       at System.Threading.Tasks.Task`1.InnerInvoke() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task_T.cs:line 486
       at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs:line 279
       at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:line 2424
       at System.Threading.ThreadPoolWorkQueue.Dispatch() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:line 950
       at System.Threading.PortableThreadPool.WorkerThread.WorkerDoWork(PortableThreadPool threadPoolInstance) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:line 134
       at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:line 110
       at System.Threading.Thread.StartCallback() in /_/src/coreclr/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs:line 116
    ----- end Wed 02/25/2026  8:30:50.94 ----- exit code -2146232797 ----------------------------------------------------------
    
  11. added this to the 11.0.0 milestone on Mar 17, 2026
  12. removed
    untriaged
    on Mar 17, 2026
  13. mangod9 commented on Mar 19, 2026

    @mangod9
    Member

    copilot provided this analysis:

     Root cause: missing acquire barrier on ARM64 in AsyncOperation.SignalCompletion
    
      OnCompleted uses the standard publication idiom — write data, then publish via a release fence:
    
       _continuationState = state;   // write data (plain store)
       Interlocked.CompareExchange(ref _continuation, continuation, null);  // publish (release)
    
      SignalCompletion reads the publication with a plain load (no acquire), short-circuiting the CAS:
    
       if (_continuation is not null ||   // ← plain LDR — no acquire on ARM64!
           Interlocked.CompareExchange(ref _continuation, s_completedSentinel, null) is not null)
    
      When the short-circuit fires, there's no acquire barrier before SetCompletionAndInvokeContinuation reads
      _continuationState. On ARM64's relaxed memory model, this read can speculate ahead and return a stale (null)
      value. The continuation c is s_runContinuationAction which then calls c(null) — failing Debug.Assert(state is
      RuntimeAsyncTask<T>).
    
      On x86 (TSO) all loads are implicitly acquire so this never manifests. JitStress widens the race window by
      altering instruction scheduling.
    
      Fix — change the plain load to an acquire load (LDAR on ARM64, zero-cost on x86):
    
       - if (_continuation is not null || Interlocked.CompareExchange(ref _continuation, s_completedSentinel, null) is
      not null)
       + if (Volatile.Read(ref _continuation) is not null || Interlocked.CompareExchange(ref _continuation,
      s_completedSentinel, null) is not null)
    
      This is cheaper than always running the CAS — Volatile.Read on ARM64 emits LDAR (a few cycles) vs LDAXR/STLXR
      (tens of cycles). On x86 it's identical to a plain read.
    
      Note: the Copilot suggestion of adding a barrier at AsyncOperation.cs:270-277 (the _continuationState read in
      SetCompletionAndInvokeContinuation) would be incorrect — the acquire must pair with the release on _continuation,
      not _continuationState.
    
  14. NinoFloris commented on Mar 31, 2026

    @NinoFloris
    Contributor

    This was addressed in ManualResetValueTaskSourceCore in 3c25f59#diff-2e8d67cb44ae1feafd4904c162a22a6d971210cf251f9a60256f10536ac16bc8R216. AsyncOperation seems to have borrowed a lot of this code when it was written, but it was not kept in sync afterwards (it might be worthwhile to see if more can be shared).

    The rationale reads correct to me: any load of _continuation must be prevented from reordering with the later loads of fields that were mutated before the _continuation release fence. I have actually had real issues with exactly this reordered read on an unfixed copy of MRVTSC code on my arm64 mac. AsyncOperation seems to be affected by the same issue, the Volatile.Read on _continuation is the right fix for it.

  15. added a commit that references this issue on Apr 1, 2026
    89d7d8e
  16. jakobbotsch commented on Apr 1, 2026

    @jakobbotsch
    Member

    This was addressed in ManualResetValueTaskSourceCore in 3c25f59#diff-2e8d67cb44ae1feafd4904c162a22a6d971210cf251f9a60256f10536ac16bc8R216. AsyncOperation seems to have borrowed a lot of this code when it was written, but it was not kept in sync afterwards (it might be worthwhile to see if more can be shared).

    The rationale reads correct to me: any load of _continuation must be prevented from reordering with the later loads of fields that were mutated before the _continuation release fence. I have actually had real issues with exactly this reordered read on an unfixed copy of MRVTSC code on my arm64 mac. AsyncOperation seems to be affected by the same issue, the Volatile.Read on _continuation is the right fix for it.

    @NinoFloris Thanks for pointing at that!

  17. locked and limited conversation to collaborators on May 1, 2026
  18. added a commit that references this issue on Jul 15, 2026
    fa97c27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.Threading.Tasksblocking-clean-ciruntime-async

Type

No type

Projects

  • Status
    No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions