Repository navigation
fix(client-v2): record connection times only when metrics are enabled - #3309
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 32c65d7. Configure here.
| PoolingHttpClientConnectionManager phccm = connMgrBuilder.build(); | ||
| poolControl = phccm; | ||
| if (metricsRegistry != null) { | ||
| connectionFactory.enableMetrics(); |
There was a problem hiding this comment.
Metrics stay enabled after bind failure
Medium Severity
enableMetrics() runs before the Micrometer binders and is not turned off when registration fails. The client then keeps enqueueing connection times with no gauge calling getTime(), so the unbounded times queue this change addresses can still grow for the lifetime of the Client.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 32c65d7. Configure here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
MeteredManagedHttpClientConnectionFactory.createConnectionadds the connection creation time to aConcurrentLinkedQueueon every new pooled connection, but the queue is only drained bygetTime(), 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 injdbc-v2), one queue node is retained per new connection for the life of theClient.The factory now records times only after
enableMetrics()is called, whichHttpAPIClientHelperdoes only when a metrics registry is present, right before the gauge is bound. Behaviour with a registry is unchanged.Closes #3253
Checklist
MeteredConnectionFactoryTest: nothing is queued without metrics; times are recorded and drained once enabled. The first test fails before the fix with expected 0, found 10.)history/latest/3253.md)This PR was prepared with the assistance of an AI coding tool (Claude); the change was reviewed before submission.
Note
Low Risk
Targeted leak fix behind a flag; metrics-enabled behaviour is unchanged and covered by new unit tests.
Overview
Fixes a memory leak in pooled HTTP clients when no metrics registry is configured (the default for
client-v2andjdbc-v2).MeteredManagedHttpClientConnectionFactorypreviously appended every new connection’s creation duration to an internal queue, but that queue is drained only viagetTime()when Micrometer binds the connect-time gauge. Without a registry, entries were never removed and grew with each new connection for the client’s lifetime.The factory now gates timing behind
enableMetrics(), whichHttpAPIClientHelpercalls only when a metrics registry is present.createConnectionskips queueing when metrics are off; behaviour with Micrometer unchanged. Unit tests inMeteredConnectionFactoryTestcover both paths, andhistory/latest/3253.mddocuments the fix for #3253.Reviewed by Cursor Bugbot for commit 32c65d7. Bugbot is set up for automated code reviews on this repo. Configure here.