Open newwdles opened 1 month ago
This issue in jersey client https://github.com/eclipse-ee4j/jersey/issues/5710 mention that a leak can occur, it is fixed in 3.1.8 (the version we are using), however the NonInjectionManager#dispose() is not called when using ApiClient#requestJWTUserToken (which build a temporary Client).
We have a rest service which use docusign esign java client. The application is based on spring boot 3 and webflux. It use this code to refresh the token (boiler plate removed for clarity) :
This trigger a refresh of the token 1 minutes before the token expire, the loadApiCLient is as follow :
We are seeing memory leaks and OOM in our stage environnement : Here we can see a lot of com.fasterxml.jackson.databind.deser.BeanDeserializer instances are taking 166mo, the GC just passed before the heap dump and thoses instances are still referenced.
Looking at the root path to GC we can see that some internal objects of jersey are kept in a thread local, they in turn reference the docusign esign ApiCLient which reference some jackson classes, which internally reference the BeanDeserializer classes.
Disabling the multithreading does not solve the issue, nor does reusing the ApiClient or using apiClient.getHttpClient().close(); This make sense as it seems that a new instance of org.glassfish.jersey.client.innate.inject.NonInjectionManager.TypedInstances is created with each call to com.docusign.esign.client.ApiClient#requestJWTUserToken, this is turn create a new ThreadLocal, resulting in a leak.
The jersey code is quite complicated so i'm having trouble pinpointing the exact cause, i will post more details as i progress in my research.