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

Unexpected exception: System.Net.Quic.QuicException(ConnectionIdle) - The connection timed out from inactivity. #49780

Open
1 task done
pavelsavara opened this issue Aug 1, 2023 · 4 comments
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions HTTP3

Comments

@pavelsavara
Copy link
Member

pavelsavara commented Aug 1, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

edit and continue session failed

Expected Behavior

start the app again after browser reload

Steps To Reproduce

  • in this repo
  • in src\Components\WebAssembly\Samples\HostedBlazorWebassemblyApp\Server
  • run dotnet watch -c Debug
  • load the app in the browser and hit F5/reload page

Exceptions (if any)

Server side

Unexpected exception in QuicConnectionContext.AcceptAsync: System.Net.Quic.QuicException: The connection timed out from inactivity.
   at System.Net.Quic.QuicConnection.HandleEventShutdownInitiatedByTransport(_SHUTDOWN_INITIATED_BY_TRANSPORT_e__Struct& data)
   at System.Net.Quic.QuicConnection.HandleConnectionEvent(QUIC_CONNECTION_EVENT& connectionEvent)
   at System.Net.Quic.QuicConnection.NativeCallback(QUIC_HANDLE* connection, Void* context, QUIC_CONNECTION_EVENT* connectionEvent)
--- End of stack trace from previous location ---
   at System.Net.Quic.QuicConnection.AcceptInboundStreamAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal.QuicConnectionContext.AcceptAsync(CancellationToken cancellationToken) in C:\Dev\aspnetcore\src\Servers\Kestrel\Transport.Quic\src\Internal\QuicConnectionContext.cs:line 96
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal.QuicConnectionContext.AcceptAsync(CancellationToken cancellationToken) in C:\Dev\aspnetcore\src\Servers\Kestrel\Transport.Quic\src\Internal\QuicConnectionContext.cs:line 96
   at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.ExecutionContextCallback(Object s)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining)
   at System.Threading.Tasks.Task.RunContinuations(Object continuationObject)
   at System.Threading.Tasks.Task.FinishSlow(Boolean userDelegateExecute)
   at System.Threading.Tasks.Task.TrySetException(Object exceptionObject)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetException(Exception exception, Task`1& taskField)
   at System.Net.Quic.QuicConnection.AcceptInboundStreamAsync(CancellationToken cancellationToken)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecutionContextCallback(Object s)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

.NET Version

8.0.100-rc.1.23381.2

Anything else?

No response

@pavelsavara pavelsavara added area-blazor Includes: Blazor, Razor Components arch-wasm labels Aug 1, 2023
@javiercn javiercn added feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI and removed area-blazor Includes: Blazor, Razor Components arch-wasm labels Aug 2, 2023
@mkArtakMSFT mkArtakMSFT modified the milestones: backlog, Backlog Oct 6, 2023
@ghost
Copy link

ghost commented Oct 6, 2023

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@mkArtakMSFT
Copy link
Member

@pavelsavara can you try this out with the latest RTM build and see if it's still a problem? Thanks!

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@amcasey amcasey changed the title [blazor wasm] dotnet watch - System.Net.Quic.QuicException: The connection timed out from inactivity. Unexpected exception: System.Net.Quic.QuicException(ConnectionIdle) - The connection timed out from inactivity. Sep 20, 2024
@amcasey amcasey modified the milestones: Backlog, .NET 10 Planning Sep 20, 2024
@amcasey amcasey added HTTP3 area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed investigate area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) triaged labels Sep 20, 2024
@amcasey
Copy link
Member

amcasey commented Sep 20, 2024

Repro: Update Program.cs in Http3SampleApp:

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Net;
using System.Net.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.AspNetCore.Server.Kestrel.Https;
using Microsoft.Extensions.Logging.Abstractions;

namespace Http3SampleApp;

public class Program
{
    public static void Main(string[] args)
    {
        Environment.SetEnvironmentVariable("ASPNETCORE_HOSTINGSTARTUPASSEMBLIES", null);

        var hostBuilder = new HostBuilder()
            .ConfigureLogging((_, factory) =>
            {
                factory.SetMinimumLevel(LogLevel.Information);
                factory.AddSimpleConsole(o => o.TimestampFormat = "[HH:mm:ss.fff] ");
            })
            .ConfigureWebHost(webHost =>
            {
                var cert = CertificateLoader.LoadFromStoreCert("localhost", StoreName.My.ToString(), StoreLocation.CurrentUser, false);

                webHost.UseKestrel()
                .ConfigureKestrel((context, options) =>
                {
                    options.Limits.KeepAliveTimeout = TimeSpan.FromSeconds(500);

                    options.ListenLocalhost(5001, listenOptions =>
                    {
                        listenOptions.Protocols = HttpProtocols.Http3;
                        listenOptions.UseHttps();
                    });
                })
                .UseStartup<Startup>();
            });

        var host = hostBuilder.Build();

        // Listener needs to be configured before host (and HTTP/3 endpoints) start up.
        using var httpEventSource = new HttpEventSourceListener(NullLoggerFactory.Instance);// host.Services.GetRequiredService<ILoggerFactory>());

        host.Run();
    }
}

Client app:

var client = new HttpClient()
{
    BaseAddress = new Uri("https://localhost:5001"),
    DefaultRequestVersion = new Version(3, 0),
    DefaultVersionPolicy = HttpVersionPolicy.RequestVersionExact,
};

try
{
    Console.WriteLine("Requesting /");
    var response = await client.GetAsync("/");
    response.EnsureSuccessStatusCode();

    var data = await response.Content.ReadAsStringAsync();
    Console.WriteLine(data);
}
catch (HttpRequestException e)
{
    Console.WriteLine($"Request error: {e.Message}");
}

Thread.Sleep(TimeSpan.FromSeconds(30)); // ConnectionIdle with Sleep, ConnectionTimeout without
client.Dispose();

@amcasey
Copy link
Member

amcasey commented Sep 20, 2024

As noted here, even though we set the server's idle timeout to be infinite, the client has its own timeout. As a result, that exception is less impossible than we seem to have expected.

The fix for the assert is probably to add a catch block like this for ConnectionIdle.

However, we should also think through the scenario and ensure that the Http3ErrorCode and the end reason are being set correctly.

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

No branches or pull requests

6 participants