From 84f6caa9a08639e741321aab3d3c5d4391ed3639 Mon Sep 17 00:00:00 2001 From: Dwi Siswanto Date: Mon, 3 Nov 2025 18:19:22 +0700 Subject: [PATCH] fix: close idle conns for `HTTPClient2` to prevent memory leak The HTTPClient2 instance was being created on every `NewClient()` call but its idle connections were never closed, leading to memory accumulation. While HTTPClient2 is only used as a fallback for HTTP/2 protocol errors, it still allocates ~45MB of per client instance (24MB for the client + 21MB for HTTP/2 transport config). This commit make sure that when `KillIdleConn` is enabled, both `HTTPClient` and `HTTPClient2` have their idle connections properly closed, preventing the memory leak in scenarios where multiple client instances are created. Fixes #482. Signed-off-by: Dwi Siswanto --- do.go | 1 + 1 file changed, 1 insertion(+) diff --git a/do.go b/do.go index 06a13d0..f92ef4c 100644 --- a/do.go +++ b/do.go @@ -151,6 +151,7 @@ func (c *Client) closeIdleConnections() { } else { c.requestCounter.Store(0) c.HTTPClient.CloseIdleConnections() + c.HTTPClient2.CloseIdleConnections() } } }