question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory leak with Request Scope and Fault Tolerance

See original GitHub issue

Environment 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:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
gmpattercommented, Jul 26, 2021

@spericas I’ve tested #3199 and #3194 with latest snapshot locally and both are resolved. Thanks!

0reactions
spericascommented, Jul 26, 2021

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Memory Leak Detection Algorithms in the Cloud-based ... - arXiv
Abstract—A memory leak in an application deployed on the cloud can affect the availability and reliability of the application.
Read more >
Understanding Memory Leaks in Java - Baeldung
A Memory Leak is a situation where there are objects present in the heap that are no longer used, but the garbage collector...
Read more >
How To Detect and Prevent Memory Leaks | Scout APM Blog
Memory leak is the gradual loss of available computer memory when a program repeatedly fails to return memory it obtained for temporary use....
Read more >
Code Sample: Find Your Leaked Persistent Memory Objects ...
Describes the problem of memory leaks in persistent memory programming, then shows how to find and fix a memory leak in a simple...
Read more >
(PDF) Memory Leak Detection Algorithms in the Cloud-based ...
A memory leak in an application deployed on the cloud can affect the availability and reliability of the application.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found