Skip to content

Unexpected exception type in Http3RequestStream.SendAsync: System.Net.Quic.QuicException: Operation aborted. #111507

Closed

Description

@jkotas

Build Information

Build: https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=919979
Build error leg or test failing: System.Net.Http.Functional.Tests.WorkItemExecution
Pull request: #111321

Error Message

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

{
  "ErrorMessage": "Unexpected exception type in Http3RequestStream.SendAsync: System.Net.Quic.QuicException: Operation aborted.",
  "ErrorPattern": "",
  "BuildRetry": false,
  "ExcludeConsoleLog": false
}

Known issue validation

Build: 🔎 https://dev.azure.com/dnceng-public/public/_build/results?buildId=919979
Error message validated: [Unexpected exception type in Http3RequestStream.SendAsync: System.Net.Quic.QuicException: Operation aborted.]
Result validation: ✅ Known issue matched with the provided build.
Validation performed at: 1/16/2025 7:29:28 PM UTC

Report

Build Definition Test Pull Request
919979 dotnet/runtime System.Net.Http.Functional.Tests.WorkItemExecution #111321

Summary

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

Activity

  1. added
    blocking-clean-ci
    Known Build Error
    on Jan 16, 2025
  2. ghost added
    needs-area-label
    on Jan 16, 2025
  3. added
    untriaged
    on Jan 16, 2025
  4. added
    untriaged
    and removed
    untriaged
    needs-area-label
    on Jan 16, 2025
  5. dotnet-policy-service commented on Jan 16, 2025

    @dotnet-policy-service
    Contributor

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

  6. self-assigned this
    on Jan 17, 2025
  7. ManickaP commented on Jan 17, 2025

    @ManickaP
    Member

    It's a race between retrying the rejected request and processing GO_AWAY.
    The failing test is SendAsync_RequestRejected_ClientRetries.

    Root cause in details:

    Details
    STACK 65
    << Awaiting: 000073c0fcee81c8 00007401188eb020 System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable<System.Object>+ConfiguredValueTaskAwaiter >>
      000073c0fcee81e8 00007401189004e8 (0) System.Net.Quic.QuicListener+<AcceptConnectionAsync>d__15
        000073c0fcee8238 0000740118900f20 (0) System.Net.Test.Common.Http3LoopbackServer+<EstablishHttp3ConnectionAsync>d__6
          000073c0fcee8288 0000740119caab70 (0) System.Net.Test.Common.Http3LoopbackServer+<EstablishGenericConnectionAsync>d__7
            000073c0fcdeb718 0000740119cc8228 (6) System.Net.Http.Functional.Tests.HttpClientHandlerTest_Http3+<>c__DisplayClass11_0+<<SendAsync_RequestRejected_ClientRetries>b__0>d
              000073c0fcdf9538 00007401180480c8 ( ) System.Threading.Tasks.UnwrapPromise<System.Threading.Tasks.VoidTaskResult>
                000073c0fcdf9850 0000740118238d58 ( ) System.Threading.Tasks.ContinuationTaskFromTask {System.Threading.Tasks.TaskTimeoutExtensions+<>c__DisplayClass11_0.<WhenAllOrAnyFailedCore>b__0(System.Threading.Tasks.Task)}
    

    There's only one client connection and there are actually 3 retries of the same request. The first attempt (stream id 0) gets rejected on:


    The second retry (stream id 4) gets rejected via:
    In the meantime, there's GO_AWAY with stream id 0 on the way to the client.
    Client receives GO_AWAY and first thing it does (outside of lock, before setting _firstRejectedStreamId) is InvalidateHttp3Connection (this is happening on a separate thread stemming from control stream processing): https://github.com/dotnet/runtime/blob/4de59c4db6a2357532865d1805ee8b517ca4ab60/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3Connection.cs#L400C19-L400C44
    Now we have to switch contexts back to the request retry, the H3Connection is still not removed from the pool ==> for the third time, we attempt to send the request on it:
    QuicConnection? conn = _connection;
    if (conn != null)
    {
    quicStream = await conn.OpenOutboundStreamAsync(QuicStreamType.Bidirectional, cancellationToken).ConfigureAwait(false);
    requestStream = new Http3RequestStream(request, this, quicStream);
    lock (SyncObj)
    {
    if (_activeRequests.Count == 0)
    {
    MarkConnectionAsNotIdle();
    }
    _activeRequests.Add(quicStream, requestStream);
    }
    }

    Notice that the stream opening is not in lock (it's async). So we take the connection, open the stream and now switch back to the GO_AWAY and InvalidateHttp3Connection.

    So the GO_AWAY thread is invalidating the connection on which we've opened the stream (stream id 8), but not yet added it into _activeRequests. So we set dispose the connection:

    public override void Dispose()
    {
    lock (SyncObj)
    {
    if (_firstRejectedStreamId == -1)
    {
    _firstRejectedStreamId = long.MaxValue;
    CheckForShutdown();
    }
    }
    }

    Setting _firstRejectedStreamId to long.MaxValue and and invoking CheckForShutdown (note that _activeRequests is still empty):
    _connectionClosedTask ??= _connection.CloseAsync((long)Http3ErrorCode.NoError).AsTask();

    And we end up closing the connection from our side ==> which is the source of System.Net.Quic.QuicException: Operation aborted (locally closed connection).

    And now back to the retry, we add the request into _activeRequests and continue in SendAsync, we also evaluate goAway as not-applicable since our stream id 8 is smaller than long.MaxValue:

    bool goAway;
    lock (SyncObj)
    {
    goAway = _firstRejectedStreamId != -1 && requestStream.StreamId >= _firstRejectedStreamId;
    }

    And we end up sending the request:
    Task<HttpResponseMessage> responseTask = requestStream.SendAsync(cancellationToken);

    But the connection is closed, the stream received SHUTDOWN_COMPLETE:

    // It's local shutdown by app, this side called QuicConnection.CloseAsync, throw QuicError.OperationAborted.
    (shutdownByApp: true, closedRemotely: false) => ThrowHelper.GetOperationAbortedException(),

    And the first operation on the stream blows up with QuicException(OperationAborted) which we can see in the console log:

    Process terminated. Assertion failed.
    Unexpected exception type in Http3RequestStream.SendAsync: System.Net.Quic.QuicException: Operation aborted.
       at System.Net.Quic.ResettableValueTaskSource.TryComplete(Exception exception, Boolean final) in /_/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/ResettableValueTaskSource.cs:line 177
       at System.Net.Quic.ResettableValueTaskSource.TrySetException(Exception exception, Boolean final) in /_/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/ResettableValueTaskSource.cs:line 237
       at System.Net.Quic.QuicStream.HandleEventShutdownComplete(_SHUTDOWN_COMPLETE_e__Struct& data) in /_/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs:line 642
       at System.Net.Quic.QuicStream.HandleStreamEvent(QUIC_STREAM_EVENT& streamEvent) in /_/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs:line 665
       at System.Net.Quic.QuicStream.NativeCallback(QUIC_HANDLE* stream, Void* context, QUIC_STREAM_EVENT* streamEvent) in /_/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs:line 694
    --- End of stack trace from previous location ---
       at System.Net.Quic.ResettableValueTaskSource.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) in /_/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/ResettableValueTaskSource.cs:line 251
       at System.Net.Http.Http3RequestStream.SendAsync(CancellationToken cancellationToken) in /_/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs:line 172
       at System.Net.Http.Http3RequestStream.SendAsync(CancellationToken cancellationToken) in /_/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs:line 172
       at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 38
       at System.Net.Http.Http3RequestStream.SendAsync(CancellationToken cancellationToken)
       at System.Net.Http.Http3Connection.SendAsync(HttpRequestMessage request, Int64 queueStartingTimestamp, Activity waitForConnectionActivity, CancellationToken cancellationToken) in /_/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3Connection.cs:line 318
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs:line 179
       at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs:line 356
       at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs:line 795
       at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:line 3478
       at System.Runtime.CompilerServices.AsyncValueTaskMethodBuilder`1.SetResult(TResult result) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilderT.cs:line 47
       at System.Net.Quic.QuicConnection.OpenOutboundStreamAsync(QuicStreamType type, CancellationToken cancellationToken) in /_/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicConnection.cs:line 558
       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 264
       at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs:line 356
       at System.Threading.ThreadPoolWorkQueue.Dispatch() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:line 1118
       at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:line 127
       at System.Threading.Thread.StartHelper.RunWorker() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:line 77
    

    The console log leads an assert in Http3RequestStream.SendAsync:

    Debug.Fail($"Unexpected exception type in Http3RequestStream.SendAsync: {ex}");

    And going back through all the catch blocks, we expect System.Net.Quic.QuicException: Operation aborted only in case of cancellation or connection abort.

  8. added
    in-pr
    on Jan 20, 2025
  9. removed
    untriaged
    on Jan 21, 2025
  10. locked and limited conversation to collaborators on Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Known Build Errorarea-System.Net.Quicblocking-clean-ciin-pr

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions