Search code examples
asp.net-corehttpclient

ASP.NET Core 3.1 HttpMessageHandler cleanup cycle


I see these messages in my debug log:

[23:29:12 DBG] HttpMessageHandler expired after 120000ms for client 'default' {"EventId": {"Id": 103, "Name": "HandlerExpired"}, "SourceContext": "Microsoft.Extensions.Http.DefaultHttpClientFactory"}

[23:29:22 DBG] Starting HttpMessageHandler cleanup cycle with 1 items {"EventId": {"Id": 100, "Name": "CleanupCycleStart"}, "SourceContext": "Microsoft.Extensions.Http.DefaultHttpClientFactory"}

[23:29:22 DBG] Ending HttpMessageHandler cleanup cycle after 1.9126ms - processed: 0 items - remaining: 1 items {"EventId": {"Id": 101, "Name": "CleanupCycleEnd"}, "SourceContext": "Microsoft.Extensions.Http.DefaultHttpClientFactory"}

[23:29:32 DBG] Starting HttpMessageHandler cleanup cycle with 1 items {"EventId": {"Id": 100, "Name": "CleanupCycleStart"}, "SourceContext": "Microsoft.Extensions.Http.DefaultHttpClientFactory"}

[23:29:32 DBG] Ending HttpMessageHandler cleanup cycle after 0.1306ms - processed: 0 items - remaining: 1 items {"EventId": {"Id": 101, "Name": "CleanupCycleEnd"}, "SourceContext": "Microsoft.Extensions.Http.DefaultHttpClientFactory"}

These messages never end, but I do not use any of those in my application. I have some undisposed object, why do I always have one item?

This is my code in Startup.cs:

services.AddHttpClient("default", c =>
        {
            c.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate");
            c.Timeout = TimeSpan.FromMinutes(120);
        }).ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
        {
            Proxy = WebRequest.DefaultWebProxy,
            AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip
        });

Solution

  • This github issue discussed a similar issue, and it seems default behavior.

    And if you do not want to get the log of Microsoft.Extensions.Http.DefaultHttpClientFactory category, you can set it at log level "Information" and higher.

    "Microsoft.Extensions.Http.DefaultHttpClientFactory": "Information"