Skip to content

Commit fc163be

Browse files
authored
DelegationRule.Dispose() unsets delegation property on the queue (#28342)
* Add disposing pattern * Stash (destination) urlgroup on a field * Make test explicit
1 parent 56fde07 commit fc163be

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/Servers/HttpSys/src/DelegationRule.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
1313
public class DelegationRule : IDisposable
1414
{
1515
private readonly ILogger _logger;
16+
private readonly UrlGroup _urlGroup;
1617
private readonly UrlGroup _sourceQueueUrlGroup;
1718
private bool _disposed;
1819
/// <summary>
@@ -32,6 +33,7 @@ internal DelegationRule(UrlGroup sourceQueueUrlGroup, string queueName, string u
3233
QueueName = queueName;
3334
UrlPrefix = urlPrefix;
3435
Queue = new RequestQueue(queueName, UrlPrefix, _logger, receiver: true);
36+
_urlGroup = Queue.UrlGroup;
3537
}
3638

3739
/// <inheritdoc />
@@ -49,7 +51,7 @@ public void Dispose()
4951
_sourceQueueUrlGroup.UnSetDelegationProperty(Queue, throwOnError: false);
5052
}
5153
catch (ObjectDisposedException) { /* Server may have been shutdown */ }
52-
Queue.UrlGroup.Dispose();
54+
_urlGroup.Dispose();
5355
Queue.Dispose();
5456
}
5557
}

src/Servers/HttpSys/test/FunctionalTests/DelegateTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,11 @@ public async Task UpdateDelegationRuleTest()
186186

187187
var delegationProperty = delegator.Features.Get<IServerDelegationFeature>();
188188
destination = delegationProperty.CreateDelegationRule(queueName, receiverAddress);
189+
// Send a request to ensure the rule is fully active
190+
var responseString = await SendRequestAsync(delegatorAddress);
189191
destination?.Dispose();
190192
destination = delegationProperty.CreateDelegationRule(queueName, receiverAddress);
191-
var responseString = await SendRequestAsync(delegatorAddress);
193+
responseString = await SendRequestAsync(delegatorAddress);
192194
Assert.Equal(_expectedResponseString, responseString);
193195
destination?.Dispose();
194196
}

0 commit comments

Comments
 (0)