Skip to content

Remove premature QuicListener.IsSupported check #44755

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public QuicConnectionListener(
{
if (!QuicListener.IsSupported)
{
throw new NotSupportedException("QUIC is not supported or enabled on this platform. See https://aka.ms/aspnet/kestrel/http3reqs for details.");
throw new NotSupportedException("QUIC and HTTP/3 are not supported or enabled on this platform. See https://aka.ms/aspnet/kestrel/http3reqs for details.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a unit test for this error? We could have a test that always runs that checks for QuicListener.IsSupported and expects an error if it is false.

}

if (endpoint is not IPEndPoint listenEndPoint)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// 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.Quic;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Quic;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -20,15 +19,11 @@ public static class WebHostBuilderQuicExtensions
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
public static IWebHostBuilder UseQuic(this IWebHostBuilder hostBuilder)
{
if (QuicListener.IsSupported)
// QuicListener.IsSupported has performance costs. Always register the QUIC factory and then check for support when binding an endpoint.
return hostBuilder.ConfigureServices(services =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The presence of a registered multiplexed transport factory is tested when figuring out if an endpoint supports HTTP/3. For example:

if (hasHttp3 && _multiplexedTransportFactory is null && !(hasHttp1 || hasHttp2))

Copy link
Member Author

@halter73 halter73 Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. This isn't relevant if you have HTTP/3 disabled which is the .NET 7 default. Or if you have only HTTP/3 enabled which would throw either way.

But if you have HttpProtocols.Http1AndHttp2AndHttp3 configured which is the default in main, we have to pay the cost of the check regardless 😢. Do you think we could leverage your new CanBind API (#44537) for checking this in .NET 8?

If we backport this to 7 (which I still think we should do), we might just have to swallow the NotSupportedException thrown from BindAsync in the Http1AndHttp2AndHttp3 case. Fortunately, that's not the default in 7, and I don't see many people manually setting that unless they are running on a platform that supports QUIC.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should ask the S.N.Q team to look at improving QuicListener.IsSupported performance. See if it can be changed to avoid loading msquic.

Copy link
Member

@eerhardt eerhardt Oct 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't relevant if you have HTTP/3 disabled which is the .NET 7 default

dotnet/runtime#73153 enabled HTTP/3 for HttpClient by default for 7.0 rc1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dotnet/runtime#73153 enabled HTTP/3 for HttpClient by default for 7.0 rc1.

The developer still has to opt-in by changing the request version or policy.

{
return hostBuilder.ConfigureServices(services =>
{
services.AddSingleton<IMultiplexedConnectionListenerFactory, QuicTransportFactory>();
});
}

return hostBuilder;
services.AddSingleton<IMultiplexedConnectionListenerFactory, QuicTransportFactory>();
});
}

/// <summary>
Expand Down