runtime: Endless HttpMessageHandler cleanup cycle with C# cmdlets using .NET generic host
area-Extensions-HttpClientFactory
Hi there,
I have a c# PowerShell module with cmdlets that make use of the .NET generic host. It uses .NET standard 2.1.
Unfortunately after a few calls to the cmdlets I start to get endless debug messages in the PowerShell terminal…
dbug: Microsoft.Extensions.Http.DefaultHttpClientFactory[100]
Starting HttpMessageHandler cleanup cycle with 1 items
I looked at this thread (https://github.com/aspnet/HttpClientFactory/issues/165) and used JetBrains’ dotMemory to force a garbage collection but it doesn’t fix it.
I did the shortest path analysis below but to be honest I’m not sure entirely how to interpret it.
Any help appreciated…
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 25 (10 by maintainers)
I believe the logging is by-design. It looks to me like your Service is keeping a reference to the HttpClient and that will keep the handler rooted. The service is registered as a singleton which I think means the service will be created once and kept alive for the lifetime of the host and the host will be kept alive by the cmdlet instance. The logging is just because you’ve enabled debug level logging and this debug statement is telling you the handler is still rooted by something after time has passed.
/cc @davidfowl @maryamariyan to check my understanding here. FYI @dotnet/ncl