From e53c9b9a70654a8ec90a31009529c3219c219bfe Mon Sep 17 00:00:00 2001 From: Miha Zupan Date: Thu, 5 Dec 2024 16:27:56 +0100 Subject: [PATCH 1/2] Workaround broken .NET 9.0 HttpSys linux packages --- .../ReverseProxyServiceCollectionExtensions.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ReverseProxy/Management/ReverseProxyServiceCollectionExtensions.cs b/src/ReverseProxy/Management/ReverseProxyServiceCollectionExtensions.cs index 2a5cb65bb..e20d2e755 100644 --- a/src/ReverseProxy/Management/ReverseProxyServiceCollectionExtensions.cs +++ b/src/ReverseProxy/Management/ReverseProxyServiceCollectionExtensions.cs @@ -52,10 +52,17 @@ public static IReverseProxyBuilder AddReverseProxy(this IServiceCollection servi .AddActiveHealthChecks() .AddPassiveHealthCheck() .AddLoadBalancingPolicies() - .AddHttpSysDelegation() .AddDestinationResolver() .AddProxy(); + if (OperatingSystem.IsWindows()) + { + // Workaround for https://github.com/dotnet/aspnetcore/issues/59166 + // .NET 9.0 packages for Ubuntu ship a broken Microsoft.AspNetCore.Server.HttpSys assembly. + // Avoid loading types from that assembly on Linux unless the user explicitly tries to do so. + builder.AddHttpSysDelegation(); + } + services.TryAddSingleton(); services.AddDataProtection(); From 57b4aeeec5723f7902f5d87c1cb6b4645aaa8b54 Mon Sep 17 00:00:00 2001 From: Miha Zupan Date: Thu, 5 Dec 2024 16:43:36 +0100 Subject: [PATCH 2/2] Also handle the interface being referenced in cross-plat logic --- src/ReverseProxy/Delegation/DummyHttpSysDelegator.cs | 10 ++++++++++ .../ReverseProxyServiceCollectionExtensions.cs | 8 +++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/ReverseProxy/Delegation/DummyHttpSysDelegator.cs diff --git a/src/ReverseProxy/Delegation/DummyHttpSysDelegator.cs b/src/ReverseProxy/Delegation/DummyHttpSysDelegator.cs new file mode 100644 index 000000000..909eb8c7b --- /dev/null +++ b/src/ReverseProxy/Delegation/DummyHttpSysDelegator.cs @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace Yarp.ReverseProxy.Delegation; + +// Only used as part of a workaround for https://github.com/dotnet/aspnetcore/issues/59166. +internal sealed class DummyHttpSysDelegator : IHttpSysDelegator +{ + public void ResetQueue(string queueName, string urlPrefix) { } +} diff --git a/src/ReverseProxy/Management/ReverseProxyServiceCollectionExtensions.cs b/src/ReverseProxy/Management/ReverseProxyServiceCollectionExtensions.cs index e20d2e755..52a0a930e 100644 --- a/src/ReverseProxy/Management/ReverseProxyServiceCollectionExtensions.cs +++ b/src/ReverseProxy/Management/ReverseProxyServiceCollectionExtensions.cs @@ -10,6 +10,7 @@ using Microsoft.Extensions.Logging; using Yarp.ReverseProxy.Configuration; using Yarp.ReverseProxy.Configuration.ConfigProvider; +using Yarp.ReverseProxy.Delegation; using Yarp.ReverseProxy.Forwarder; using Yarp.ReverseProxy.Management; using Yarp.ReverseProxy.Routing; @@ -57,11 +58,16 @@ public static IReverseProxyBuilder AddReverseProxy(this IServiceCollection servi if (OperatingSystem.IsWindows()) { - // Workaround for https://github.com/dotnet/aspnetcore/issues/59166 + // Workaround for https://github.com/dotnet/aspnetcore/issues/59166. // .NET 9.0 packages for Ubuntu ship a broken Microsoft.AspNetCore.Server.HttpSys assembly. // Avoid loading types from that assembly on Linux unless the user explicitly tries to do so. builder.AddHttpSysDelegation(); } + else + { + // Add a no-op delegator in case someone is injecting the interface in their cross-plat logic. + builder.Services.TryAddSingleton(); + } services.TryAddSingleton();