Skip to content

fix: close idle conns for HTTPClient2#483

Merged
Mzack9999 merged 1 commit intomainfrom
dwisiswant0/fix/close-idle-conns-for-HTTPClient2
Nov 3, 2025
Merged

fix: close idle conns for HTTPClient2#483
Mzack9999 merged 1 commit intomainfrom
dwisiswant0/fix/close-idle-conns-for-HTTPClient2

Conversation

@dwisiswant0
Copy link
Member

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.

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 <git@dw1.io>
@dwisiswant0 dwisiswant0 requested a review from Mzack9999 November 3, 2025 11:21
@Mzack9999 Mzack9999 merged commit 129c1fd into main Nov 3, 2025
7 checks passed
@Mzack9999 Mzack9999 deleted the dwisiswant0/fix/close-idle-conns-for-HTTPClient2 branch November 3, 2025 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak: HTTPClient2 idle connections are never closed

2 participants