From eac3441cc9f4f5943a063c9a4aadadc4a80414b1 Mon Sep 17 00:00:00 2001 From: Miha Zupan Date: Thu, 5 Dec 2024 23:14:07 +0100 Subject: [PATCH] Workaround broken .NET 9.0 HttpSys linux packages (#2673) * Workaround broken .NET 9.0 HttpSys linux packages * Also handle the interface being referenced in cross-plat logic --- .../Delegation/DummyHttpSysDelegator.cs | 10 ++++++++++ .../ReverseProxyServiceCollectionExtensions.cs | 15 ++++++++++++++- 2 files changed, 24 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 2a5cb65bb..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; @@ -52,10 +53,22 @@ 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(); + } + else + { + // Add a no-op delegator in case someone is injecting the interface in their cross-plat logic. + builder.Services.TryAddSingleton(); + } + services.TryAddSingleton(); services.AddDataProtection();