Skip to content

Duplicate delegation rules should not fail #28341

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
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
11 changes: 10 additions & 1 deletion src/Servers/HttpSys/src/NativeInterop/UrlGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,16 @@ internal void SetProperty(HttpApiTypes.HTTP_SERVER_PROPERTY property, IntPtr inf

var statusCode = HttpApi.HttpSetUrlGroupProperty(Id, property, info, infosize);

if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
if (statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_ALREADY_EXISTS
&& property == HttpApiTypes.HTTP_SERVER_PROPERTY.HttpServerDelegationProperty)
{
/* Swallow file already exists exception
* Delegation property has been set by
* another rule referencing the same UrlGroup
*/
return;
}
else if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
{
var exception = new HttpSysException((int)statusCode);
_logger.LogError(LoggerEventIds.SetUrlPropertyError, exception, "SetUrlGroupProperty");
Expand Down
41 changes: 41 additions & 0 deletions src/Servers/HttpSys/test/FunctionalTests/DelegateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Testing;
using Xunit;
Expand Down Expand Up @@ -144,6 +146,45 @@ public async Task DelegateAfterRequestBodyReadShouldThrow()
destination?.Dispose();
}

[ConditionalFact]
[DelegateSupportedCondition(true)]
public async Task DuplicateDelegationRuleTest()
{
var queueName = Guid.NewGuid().ToString();
using var receiver = Utilities.CreateHttpServer(out _, async httpContext =>
{
await httpContext.Response.WriteAsync(_expectedResponseString);
},
options =>
{
options.RequestQueueName = queueName;
options.UrlPrefixes.Add("http://localhost:0");
options.UrlPrefixes.Add("http://localhost:0");
});

var receiverAddresses = receiver.Features.Get<IServerAddressesFeature>().Addresses.ToList();

DelegationRule destination0 = default;
DelegationRule destination1 = default;

using var delegator = Utilities.CreateHttpServer(out var delegatorAddress, httpContext =>
{
var delegateFeature = httpContext.Features.Get<IHttpSysRequestDelegationFeature>();
// Let's pick the rule we didn't set the delegation property on
delegateFeature.DelegateRequest(destination1);
return Task.CompletedTask;
});

var delegationProperty = delegator.Features.Get<IServerDelegationFeature>();
destination0 = delegationProperty.CreateDelegationRule(queueName, receiverAddresses[0]);
destination1 = delegationProperty.CreateDelegationRule(queueName, receiverAddresses[1]);

var responseString = await SendRequestAsync(delegatorAddress);
Assert.Equal(_expectedResponseString, responseString);
destination0?.Dispose();
destination1?.Dispose();
}

[ConditionalFact]
[DelegateSupportedCondition(false)]
public async Task DelegationFeaturesAreNull()
Expand Down