Memory leak with Request Scope and Fault Tolerance
See original GitHub issueEnvironment Details
- Helidon Version: 2.3.0
- Helidon MP
- JDK version: 11.0.9
- OS: MacOS 11.4
Problem Description
With Helidon MP 2.3.0 I’m seeing a potential memory leak in our application. In a heap dump from one load test I could see 595,000 instances of org.jboss.weld.contexts.SerializableContextualInstanceImpl with reference to an instance of Hk2RequestScope being hung on to by HelidonCdi instanceCache.
It seems to happen when injecting ServerRequest into a resource to use in an endpoint, while also using a Fault Tolerance annotation on the endpoint. Without the FT annotation I’m not seeing any instance of org.jboss.weld.contexts.SerializableContextualInstanceImpl created with reference to Hk2RequestScope.
Steps to reproduce
Create a new helidon-quickstart-mp app.
Inject ServerRequest and update the GET endpoint to use ServerRequest. Also add @Timeout annotation to the GET endpoint:
@Context
ServerRequest mServerRequest;
@Path("/{name}")
@GET
@Produces(MediaType.APPLICATION_JSON)
@Timeout
public JsonObject getMessage(@PathParam("name") String name) {
return createResponse(name + " tenant " + mServerRequest.headers().first("X-CCTenantId").get());
}
Make n number of requests to the endpoint:
for ((i=1;i<=1000;i++)); do curl -v --header "X-CCTenantID: tenant1" "localhost:8080/greet/gareth"; done
Take a heap dump, you can see n number of SerializableContextualInstanceImpl with instance=org.glassfish.jersey.inject.hk2.Hk2RequestScope. Eclipse MAT OQL query:
SELECT instance AS instance FROM org.jboss.weld.contexts.SerializableContextualInstanceImpl s WHERE instance.toString().contains("org.glassfish.jersey.inject.hk2.Hk2RequestScope")
Force GC, take another heap dump and still see n number of SerializableContextualInstanceImpl.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
@spericas I’ve tested #3199 and #3194 with latest snapshot locally and both are resolved. Thanks!
@gmpatter A couple of issues you reported recently have been fixed in SNAPSHOT. Do you have some time to build from sources and try the fixes? Should be useful before the next release.