-
Notifications
You must be signed in to change notification settings - Fork 981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak in MicrometerHttpClientInterceptor
#3920
Comments
@Stephan202 I'm afraid I haven't found a way to properly fix this in the 4.x generation of the client. We cannot apply the same fix as #3801 as the contracts don't exist. See #3932 for context: we might drop support for the 4.x async client as a result. |
Tnx for the update @bclozel! On our side we've worked around this issue by migrating the relevant client from |
@Stephan202 Thanks for letting us know. FYI as of Spring Framework 6 and Spring Boot 3, both |
Describe the bug
In
MicrometerHttpClientInterceptor
aConcurrentHashMap
is used to trackTimer.ResourceSamples
byHttpContext
. The sample is registered when the request is fired, and only deregistered if a response is received. In particular, if the request is cancelled while in flight, then the associated map entry is never cleared.This introduces a memory leak. We noticed this issue because (in a very roundabout manner involving a very complex reactive chain; but that's not relevant for this issue) we have a situation in which some of the cached
HttpContext
s retain a few humongous objects that would otherwise have been garbage collected. As a result one of our applications frequently gets OOMKilled.Environment
org.apache.httpcomponents:httpasyncclient:jar:4.1.5
.main
(see reproduction description below).To Reproduce
main
:MicrometerHttpClientInterceptor:76
andMicrometerHttpClientInterceptor:80
.cancelledRequest
test in debug mode.Expected behavior
No memory leak 🙃.
Additional context
This also appears to impact the
io.micrometer.core.instrument.binder.httpcomponents.hc5
variant of the class. I see that in #3801 these classes are deleted, so maybe that PR also resolves this issue. I didn't investigate closer. CC @cachescrubber.The text was updated successfully, but these errors were encountered: