Is there an existing issue for this?
Describe the bug
Hey folks,
When we apply AddServiceDiscovery(); to builder.Services and especially when we apply AddServiceDiscovery(); on IHttpClientBuilder in ConfigureHttpClientDefaults in application which uses IHttpClientFactory, it seems that underlying HttpServiceEndpointResolver never disposes its internal System.Threading.Timer. Over days, this accumulates, causing (steadily) growing memory and CPU usage. (growing CPU usage in particular)
If I'm correct, It has to do something with HandlerLifetime and HandlerChain of a HttpClient, because leak becomes even more noticeable if you lower the amount for HandlerLifetime, from default 2 minutes, to seconds for example.
Expected Behavior
When IHttpClientFactory retires and his HttpClient gets disposed, all resources attached to them, including HttpServiceEndpointResolver and its timer should be disposed.
Steps To Reproduce
https://github.com/kr3s0/LeakyClient is a minimalistic project which reproduces this issue (repro).
Exceptions (if any)
No visible exceptions
.NET Version info
- .NET 10
- Aspire 13
- Microsoft.Extensions.ServiceDiscovery 9.5.1
- Microsoft.Extensions.Http.Resilience 9.10.0
- Running in Kubernetes (Linux containers)
Anything else?
