Skip to content

Commit eac3441

Browse files
authoredDec 5, 2024··
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
1 parent 40b5a62 commit eac3441

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
namespace Yarp.ReverseProxy.Delegation;
5+
6+
// Only used as part of a workaround for https://github.com/dotnet/aspnetcore/issues/59166.
7+
internal sealed class DummyHttpSysDelegator : IHttpSysDelegator
8+
{
9+
public void ResetQueue(string queueName, string urlPrefix) { }
10+
}

‎src/ReverseProxy/Management/ReverseProxyServiceCollectionExtensions.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.Extensions.Logging;
1111
using Yarp.ReverseProxy.Configuration;
1212
using Yarp.ReverseProxy.Configuration.ConfigProvider;
13+
using Yarp.ReverseProxy.Delegation;
1314
using Yarp.ReverseProxy.Forwarder;
1415
using Yarp.ReverseProxy.Management;
1516
using Yarp.ReverseProxy.Routing;
@@ -52,10 +53,22 @@ public static IReverseProxyBuilder AddReverseProxy(this IServiceCollection servi
5253
.AddActiveHealthChecks()
5354
.AddPassiveHealthCheck()
5455
.AddLoadBalancingPolicies()
55-
.AddHttpSysDelegation()
5656
.AddDestinationResolver()
5757
.AddProxy();
5858

59+
if (OperatingSystem.IsWindows())
60+
{
61+
// Workaround for https://github.com/dotnet/aspnetcore/issues/59166.
62+
// .NET 9.0 packages for Ubuntu ship a broken Microsoft.AspNetCore.Server.HttpSys assembly.
63+
// Avoid loading types from that assembly on Linux unless the user explicitly tries to do so.
64+
builder.AddHttpSysDelegation();
65+
}
66+
else
67+
{
68+
// Add a no-op delegator in case someone is injecting the interface in their cross-plat logic.
69+
builder.Services.TryAddSingleton<IHttpSysDelegator, DummyHttpSysDelegator>();
70+
}
71+
5972
services.TryAddSingleton<ProxyEndpointFactory>();
6073

6174
services.AddDataProtection();

0 commit comments

Comments
 (0)
Please sign in to comment.