You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
io.micronaut.http.client.netty.DefaultHttpClient instances are leaking and are retained in unbalancedClients map in io.micronaut.http.client.netty.DefaultNettyHttpClientRegistry
Steps To Reproduce
In our application we have defined a http client like this:
We have noticed after a certain time, that the Java Heap was filling up to the maximum.
By analysis of the heap dump we noticed a large amount of DefaultHttpClient instances stored into the unbalancedClients map in DefaultNettyHttpClientRegistry.
and the key of this unbalancedClients map is io.micronaut.http.client.netty.DefaultNettyHttpClientRegistry.ClientKey
ClientKey class is made from the following fields:
final HttpVersionSelection httpVersion;
final String clientId;
final List<String> filterAnnotations;
final String path;
final Class<?> configurationClass;
final JsonFeatures jsonFeatures;
The problem is that httpVersion field when not null is using the type io.micronaut.http.client.HttpVersionSelection that does not provide any equals and hashCode methods.
So in the case of the ClientKey::hashCode it means that we are using an identityHashCode and using @client annotation with alpn will create a new instance of HttpVersionSelection (through DefaultNettyHttpClientRegistry#getClientKey -> HttpVersionSelection#forClientAnnotation.
Then every http client have a different hashCode that will spread across the unbalancedClients map.
Moreover the ClientKey::equals use reference equality (==) for the httpVersion field which will be always false.
It ends up creating a new http client for every request and stored into the map.
Environment Information
No response
Example Application
No response
Version
4.1.5
The text was updated successfully, but these errors were encountered:
Expected Behavior
no memory leak
Actual Behaviour
io.micronaut.http.client.netty.DefaultHttpClient
instances are leaking and are retained inunbalancedClients
map inio.micronaut.http.client.netty.DefaultNettyHttpClientRegistry
Steps To Reproduce
In our application we have defined a http client like this:
We have noticed after a certain time, that the Java Heap was filling up to the maximum.
By analysis of the heap dump we noticed a large amount of
DefaultHttpClient
instances stored into the unbalancedClients map inDefaultNettyHttpClientRegistry
.Insertion into the map is done by this:
and the key of this
unbalancedClients
map isio.micronaut.http.client.netty.DefaultNettyHttpClientRegistry.ClientKey
ClientKey class is made from the following fields:
and
equals
andhashCode
:The problem is that
httpVersion
field when not null is using the typeio.micronaut.http.client.HttpVersionSelection
that does not provide anyequals
andhashCode
methods.So in the case of the ClientKey::hashCode it means that we are using an identityHashCode and using @client annotation with
alpn
will create a new instance ofHttpVersionSelection
(throughDefaultNettyHttpClientRegistry#getClientKey
->HttpVersionSelection#forClientAnnotation
.Then every http client have a different hashCode that will spread across the
unbalancedClients
map.Moreover the
ClientKey::equals
use reference equality (==
) for thehttpVersion
field which will be always false.It ends up creating a new http client for every request and stored into the map.
Environment Information
No response
Example Application
No response
Version
4.1.5
The text was updated successfully, but these errors were encountered: