Skip to content

fix(client-v2): record connection times only when metrics are enabled - #3309

Merged
chernser merged 2 commits into
ClickHouse:mainfrom
pcbeingused333:c1692-times-queue
Nov 10, 2026
Merged

chernser merged 2 commits into
ClickHouse:mainfrom
pcbeingused333:c1692-times-queue

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

MeteredManagedHttpClientConnectionFactory.createConnection adds the connection creation time to a ConcurrentLinkedQueue on every new pooled connection, but the queue is only drained by getTime(), which only the Micrometer gauge calls, and that gauge is registered only when a metrics registry is configured. Without a registry (the default, and always in jdbc-v2), one queue node is retained per new connection for the life of the Client.

The factory now records times only after enableMetrics() is called, which HttpAPIClientHelper does only when a metrics registry is present, right before the gauge is bound. Behaviour with a registry is unchanged.

Closes #3253

Checklist


This PR was prepared with the assistance of an AI coding tool (Claude); the change was reviewed before submission.


Note

Low Risk
Targeted change to optional metrics bookkeeping in the HTTP connection factory; behavior with a configured metrics registry is unchanged.

Overview
Fixes a memory leak in the pooled HTTP client: every new connection used to push a duration into an internal queue that is only drained when the Micrometer httpcomponents.httpclient.connect.time gauge runs. Clients without a metrics registry (including jdbc-v2) never drained that queue.

MeteredManagedHttpClientConnectionFactory now records connection times only after enableMetrics(); HttpAPIClientHelper enables that when binding Micrometer metrics and calls disableMetrics() (clearing the queue) if registration fails. Unit tests cover the no-metrics, enabled, and disabled paths.

Reviewed by Cursor Bugbot for commit 120fef9. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 32c65d7. Configure here.

chernser
chernser previously approved these changes Nov 9, 2026
@chernser
chernser merged commit f9586ab into ClickHouse:main Nov 10, 2026
30 of 31 checks passed
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.

[client-v2] Connect-time queue of the pooled connection factory grows without limit when no metrics registry is set

2 participants