Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUIC] QuicConnectionContext.Abort calls connection shutdown with error code -1 #55196

Closed
1 task done
ManickaP opened this issue Apr 18, 2024 · 0 comments · Fixed by #55282
Closed
1 task done

[QUIC] QuicConnectionContext.Abort calls connection shutdown with error code -1 #55196

ManickaP opened this issue Apr 18, 2024 · 0 comments · Fixed by #55282
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions HTTP3

Comments

@ManickaP
Copy link
Member

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When client connection idles out, the server tries to close the connection but without specifying error code, probably here:

Abort(CreateConnectionAbortError(error, clientAbort), (Http3ErrorCode)_errorCodeFeature.Error);

The implementation of error code feature defaults to -1 if it was not specified:

The allowed values are positive integers up to 62 bits. If the code passed in the null, QuicConnection.CloseAsync would use the default error code specified in connection options.

This causes asserts in MsQuic library when build in Debug (in release it does nothing). We could add check in S.N.Quic, but that would break Kestrel at the moment.

Expected Behavior

Do not pass in -1 to QuicConnection.CloseAsync or QuicStream.Abort. Rather pass in null or any value between 0-2^62.

Steps To Reproduce

Use debug build of MsQuic. Start the server, start the client, send H/3 request, read response, leave the client open until the connection idles out. Look for dump.

using System.Net;
using System.Net.Security;
using Microsoft.AspNetCore.Server.Kestrel.Core;

var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel((context, options) =>
{
    options.ListenAnyIP(5001, listenOptions =>
    {
        listenOptions.Protocols = HttpProtocols.Http3;
        listenOptions.UseHttps();
    });
});
var app = builder.Build();

app.MapGet("/", () => "Hello World!");

var _ = Task.Run(() => app.Run());
var client = new HttpClient(new SocketsHttpHandler()
{
    PooledConnectionIdleTimeout = TimeSpan.FromSeconds(5),
    SslOptions = new SslClientAuthenticationOptions
    {
        RemoteCertificateValidationCallback = delegate { return true; }
    }
})
{
    DefaultRequestVersion = HttpVersion.Version30,
    DefaultVersionPolicy = HttpVersionPolicy.RequestVersionExact
};
using var response = await client.GetAsync("https://localhost:5001");
Console.WriteLine($"{await response.Content.ReadAsStringAsync()}");
await Task.Delay(TimeSpan.FromSeconds(10));

Exceptions (if any)

Dump stack:

(lldb) clrstack
OS Thread Id: 0x124e3 (1)
        Child SP               IP Call Site
00007EF1869F34A0 00007ef2161bf32c [InlinedCallFrame: 00007ef1869f34a0] 
00007EF1869F34A0 00007ef199a3cfbe [InlinedCallFrame: 00007ef1869f34a0] 
00007EF1869F3490 00007EF199A3CFBE System.Net.Quic.MsQuicApi.ConnectionShutdown(System.Net.Quic.MsQuicSafeHandle, Microsoft.Quic.QUIC_CONNECTION_SHUTDOWN_FLAGS, UInt64) [/_/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicApi.NativeMethods.cs @ 220]
00007EF1869F3550 00007EF199A431D5 System.Net.Quic.QuicConnection.CloseAsync(Int64, System.Threading.CancellationToken) [/_/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicConnection.cs @ 493]
00007EF1869F3590 00007EF1999A81B2 Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal.QuicConnectionContext.Abort(Microsoft.AspNetCore.Connections.ConnectionAbortedException) [/_/src/Servers/Kestrel/Transport.Quic/src/Internal/QuicConnectionContext.cs @ 87]
00007EF1869F35F0 00007EF1981DBFDB Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http3.Http3Connection.Abort(Microsoft.AspNetCore.Connections.ConnectionAbortedException, System.Net.Http.Http3ErrorCode) [/_/src/Servers/Kestrel/Core/src/Internal/Http3/Http3Connection.cs @ 191]
00007EF1869F36C0 00007EF198244971 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http3.Http3Connection+<ProcessRequestsAsync>d__60`1[[System.__Canon, System.Private.CoreLib]].MoveNext() [/_/src/Servers/Kestrel/Core/src/Internal/Http3/Http3Connection.cs @ 530]
00007EF1869F38A0 00007EF19ADF2032 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http3.Http3Connection+<ProcessRequestsAsync>d__60`1[[System.__Canon, System.Private.CoreLib]], Microsoft.AspNetCore.Server.Kestrel.Core]].ExecutionContextCallback(System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 289]
00007EF1869F38E0 00007EF196A95565 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs @ 179]
00007EF1869F3930 00007EF19ADF1B39 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http3.Http3Connection+<ProcessRequestsAsync>d__60`1[[System.__Canon, System.Private.CoreLib]], Microsoft.AspNetCore.Server.Kestrel.Core]].MoveNext(System.Threading.Thread) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 368]
00007EF1869F39C0 00007EF19ADF193A System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http3.Http3Connection+<ProcessRequestsAsync>d__60`1[[System.__Canon, System.Private.CoreLib]], Microsoft.AspNetCore.Server.Kestrel.Core]].MoveNext() [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 346]
00007EF1869F39E0 00007EF1999AE019 Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal.QuicConnectionContext+<AcceptAsync>d__18.MoveNext() [/_/src/Servers/Kestrel/Transport.Quic/src/Internal/QuicConnectionContext.cs @ 194]
00007EF1869F3B18 00007ef215bd3df2 [InlinedCallFrame: 00007ef1869f3b18] 
00007EF1869F3B18 00007ef196ada498 [InlinedCallFrame: 00007ef1869f3b18] 
00007EF1869F3B10 00007EF196ADA498 System.Runtime.EH.DispatchEx(System.Runtime.StackFrameIterator ByRef, ExInfo ByRef) [/_/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs @ 925]
00007EF1869F3C50 00007EF196AD9B4B System.Runtime.EH.RhThrowEx(System.Object, ExInfo ByRef) [/_/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs @ 641]
00007EF1869F7700 00007ef215c99927 [HelperMethodFrame: 00007ef1869f7700] 
00007EF1869F7820 00007EF19AE13099 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs @ 53]
00007EF1869F7840 00007EF196AFBEBC System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/TaskAwaiter.cs @ 154]
00007EF1869F7870 00007EF196AFBDC1 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task, System.Threading.Tasks.ConfigureAwaitOptions) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/TaskAwaiter.cs @ 118]
00007EF1869F7890 00007EF196D204D0 System.Runtime.CompilerServices.ValueTaskAwaiter`1[[System.__Canon, System.Private.CoreLib]].GetResult() [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/ValueTaskAwaiter.cs @ 126]
00007EF1869F78D0 00007EF1999AD96A Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal.QuicConnectionContext+<AcceptAsync>d__18.MoveNext() [/_/src/Servers/Kestrel/Transport.Quic/src/Internal/QuicConnectionContext.cs @ 96]
00007EF1869F7990 00007EF19AE14446 System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1+StateMachineBox`1[[System.__Canon, System.Private.CoreLib],[Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal.QuicConnectionContext+<AcceptAsync>d__18, Microsoft.AspNetCore.Server.Kestrel.Transport.Quic]].ExecutionContextCallback(System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/PoolingAsyncValueTaskMethodBuilderT.cs @ 392]
00007EF1869F79B0 00007EF196A95565 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs @ 179]
00007EF1869F7A00 00007EF19AE143FF System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1+StateMachineBox`1[[System.__Canon, System.Private.CoreLib],[Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal.QuicConnectionContext+<AcceptAsync>d__18, Microsoft.AspNetCore.Server.Kestrel.Transport.Quic]].MoveNext() [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/PoolingAsyncValueTaskMethodBuilderT.cs @ 413]
00007EF1869F7A30 00007EF196AB2977 System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox, Boolean) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs @ 795]
00007EF1869F7A70 00007EF196AAD966 System.Threading.Tasks.Task.RunContinuations(System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs @ 3452]
00007EF1869F7B00 00007EF196AABAD2 System.Threading.Tasks.Task.FinishSlow(Boolean) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs @ 1995]
00007EF1869F7B40 00007EF196AAD771 System.Threading.Tasks.Task.TrySetException(System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs @ 3367]
00007EF1869F7B70 00007EF196D1F14F System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, System.Private.CoreLib]].SetException(System.Exception, System.Threading.Tasks.Task`1<System.__Canon> ByRef) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 516]
00007EF1869F7BA0 00007EF199A4535A System.Net.Quic.QuicConnection+<AcceptInboundStreamAsync>d__37.MoveNext() [/_/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicConnection.cs @ 467]
00007EF1869F7CD8 00007ef215bd3df2 [InlinedCallFrame: 00007ef1869f7cd8] 
00007EF1869F7CD8 00007ef196ada498 [InlinedCallFrame: 00007ef1869f7cd8] 
00007EF1869F7CD0 00007EF196ADA498 System.Runtime.EH.DispatchEx(System.Runtime.StackFrameIterator ByRef, ExInfo ByRef) [/_/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs @ 925]
00007EF1869F7E10 00007EF196AD9B4B System.Runtime.EH.RhThrowEx(System.Object, ExInfo ByRef) [/_/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs @ 641]
00007EF1869FB8C0 00007ef215c99927 [HelperMethodFrame: 00007ef1869fb8c0] 
00007EF1869FB9E0 00007EF19AE13099 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs @ 53]
00007EF1869FBA00 00007EF196AF7865 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(System.Exception) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs @ 60]
00007EF1869FBA10 00007EF199A452EA System.Net.Quic.QuicConnection+<AcceptInboundStreamAsync>d__37.MoveNext() [/_/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicConnection.cs @ 462]
00007EF1869FBB48 00007ef215bd3df2 [InlinedCallFrame: 00007ef1869fbb48] 
00007EF1869FBB48 00007ef196ada498 [InlinedCallFrame: 00007ef1869fbb48] 
00007EF1869FBB40 00007EF196ADA498 System.Runtime.EH.DispatchEx(System.Runtime.StackFrameIterator ByRef, ExInfo ByRef) [/_/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs @ 925]
00007EF1869FBC80 00007EF196AD9B4B System.Runtime.EH.RhThrowEx(System.Object, ExInfo ByRef) [/_/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs @ 641]
00007EF1869FF730 00007ef215c99927 [HelperMethodFrame: 00007ef1869ff730] 
00007EF1869FF850 00007EF19AE13099 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs @ 53]
00007EF1869FF870 00007EF19AAB5B0D System.Threading.Channels.AsyncOperation`1[[System.__Canon, System.Private.CoreLib]].GetResult(Int16) [/_/src/libraries/System.Threading.Channels/src/System/Threading/Channels/AsyncOperation.cs @ 151]
00007EF1869FF8B0 00007EF199A451F8 System.Net.Quic.QuicConnection+<AcceptInboundStreamAsync>d__37.MoveNext() [/_/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicConnection.cs @ 458]
00007EF1869FF940 00007EF19ADF3326 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.__Canon, System.Private.CoreLib],[System.Net.Quic.QuicConnection+<AcceptInboundStreamAsync>d__37, System.Net.Quic]].ExecutionContextCallback(System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 289]
00007EF1869FF960 00007EF196A95565 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) [/_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs @ 179]
00007EF1869FF9B0 00007EF19ADF3150 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.__Canon, System.Private.CoreLib],[System.Net.Quic.QuicConnection+<AcceptInboundStreamAsync>d__37, System.Net.Quic]].MoveNext(System.Threading.Thread) [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 368]
00007EF1869FFA30 00007EF19ADF2E5A System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.__Canon, System.Private.CoreLib],[System.Net.Quic.QuicConnection+<AcceptInboundStreamAsync>d__37, System.Net.Quic]].MoveNext() [/_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs @ 346]
00007EF1869FFA50 00007EF196A9EB67 System.Threading.ThreadPoolWorkQueue.Dispatch() [/_/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs @ 913]
00007EF1869FFAC0 00007EF196AA7413 System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart() [/_/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs @ 128]
00007EF1869FFCD0 00007ef215c99927 [DebuggerU2MCatchHandlerFrame: 00007ef1869ffcd0] 

.NET Version

9.0.100-preview.4.24177.8

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Apr 18, 2024
@ManickaP ManickaP added HTTP3 and removed NativeAOT labels Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions HTTP3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant