In my .NET5 WebApi application, I am continuously getting below in the log:
[2022-03-07 13:34:34 DBG] Ending HttpMessageHandler cleanup cycle after 0.0348ms - processed: 0 items - remaining: 2 items
[2022-03-07 13:34:44 DBG] Starting HttpMessageHandler cleanup cycle with 2 items
[2022-03-07 13:34:44 DBG] Ending HttpMessageHandler cleanup cycle after 0.0064ms - processed: 0 items - remaining: 2 items
[2022-03-07 13:34:54 DBG] Starting HttpMessageHandler cleanup cycle with 2 items
[2022-03-07 13:34:54 DBG] Ending HttpMessageHandler cleanup cycle after 0.0031ms - processed: 0 items - remaining: 2 items
[2022-03-07 13:35:04 DBG] Starting HttpMessageHandler cleanup cycle with 2 items
[2022-03-07 13:35:04 DBG] Ending HttpMessageHandler cleanup cycle after 0.0044ms - processed: 0 items - remaining: 2 items
[2022-03-07 13:35:14 DBG] Starting HttpMessageHandler cleanup cycle with 2 items
[2022-03-07 13:35:14 DBG] Ending HttpMessageHandler cleanup cycle after 0.0121ms - processed: 0 items - remaining: 2 items
[2022-03-07 13:35:24 DBG] Starting HttpMessageHandler cleanup cycle with 2 items
This continues to happen, sometimes endlessly. Seems it's a cleanup cycle and takes up to long minutes to finish. Can anyone help me to understand why this is happening? and how to resolve it?
After searching a bit, I found that it's actually a log generated during Http cleanup cycle from .net. It's actually not a problem, rather some helpful logs.
The HttpMessageHandler class in .NET uses connection pooling to improve performance when making multiple HTTP requests to the same endpoint. When a request is made, the HttpMessageHandler creates a new HttpClientHandler and HttpClient instance, and adds them to the connection pool.
After the request is completed, the HttpMessageHandler instance will release the HttpClient and HttpClientHandler instances back to the connection pool. This process is known as cleanup.
You may see logs related to the cleanup cycle because some logging frameworks will log whenever an object is disposed or finalized, which happens during the cleanup process. These logs can be useful for debugging or performance analysis, but they can also be noisy and clutter up your logs.
If you are seeing an excessive number of cleanup cycle logs, it could be a sign of a performance or resource usage issue. For example, if you are creating and disposing of HttpMessageHandler instances too frequently, you may be putting unnecessary strain on the connection pool and causing excessive cleanup cycles. In that case, you may want to consider reusing HttpMessageHandler instances or optimizing your usage patterns to reduce the number of requests made.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With