Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WeakConcurrentMap memory leak #5316

Merged

Conversation

ozoz03
Copy link
Contributor

@ozoz03 ozoz03 commented Feb 7, 2022

We noticed that opentelemetry javaagent produces a memory leak and root class for this is io.opentelemetry.javaagent.tooling.muzzle.AgentCachingPoolStrategy as you can see from heap dump analysis:

Screenshot 2022-02-07 at 16 28 09

From what can see in the code AgentCachingPoolStrategy uses WeakLockFreeCache

final Cache<ClassLoader, WeakReference<ClassLoader>> loaderRefCache = Cache.weak();

and it only calls the method computeIfAbsent() on it

computeIfAbsent() makes calls to only two methods of the underlying WeekConcurrentMap.WithInlinedExpunction delegate object: getIfPresent() and putIfAbsent()

But WeekConcurrentMap.WithInlinedExpunction doesn't override those two methods and, thus, the expungeStaleEntries() method is not called and the weak keys are not removed from the map.

We think the described issue is the root cause of the observed memory leak and this pull request should fix it.


Related to #5265

@ozoz03 ozoz03 requested a review from a team as a code owner February 7, 2022 14:47
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 7, 2022

CLA Signed

The committers are authorized under a signed CLA.

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@trask trask added this to the 1.11.0 milestone Feb 8, 2022
@trask trask merged commit eeac67b into open-telemetry:main Feb 8, 2022
@vinaya-devopsnow
Copy link

thanks

RashmiRam pushed a commit to RashmiRam/opentelemetry-auto-instr-java that referenced this pull request May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants