Memory leak in MicrometerHttpClientInterceptor
#3920
Labels
bug
A general bug
instrumentation
An issue that is related to instrumenting a component
superseded
An issue that has been superseded by another
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: