Skip to content

JarFile can cause memory issues when running on Java 11+ #22991

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

Closed
alexey-anufriev opened this issue Aug 17, 2020 · 3 comments
Closed

JarFile can cause memory issues when running on Java 11+ #22991

alexey-anufriev opened this issue Aug 17, 2020 · 3 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@alexey-anufriev
Copy link

Description

After upgrade from Spring Boot 2.2.6 to 2.2.7 application started consuming much more memory.
In particular Heap Dump shows significantly higher number of instances of type:
org.springframework.boot.loader.jar.JarFile.

Heap Dump (v2.2.6) is here.
It contains the following number of instances:
v226

Heap Dump (v2.2.7) is here.
It contains the following number of instances:
v227

The number of instances is significantly higher.

Reason

After checking the history of related changes there is a couple of commits that worth to be checked:

Create new JarFile instance for URL connections

Attempt to prevent JarFiles from being left open

Attempt to prevent JarFiles from being left open

Steps to reproduce

The following repository can be used:
https://github.com/alexey-anufriev/spring-boot-2.2.7-memory-leak#steps-to-reproduce

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 17, 2020
@philwebb
Copy link
Member

philwebb commented Aug 18, 2020

Thanks for the sample application, it's been very helpful. My initial thoughts are that commit
c85918b may have caused the problem, and it's likely to only occur on Java 11.

From the profiler, it looks like java.util.zip.ZipFile.CleanableResource.FinalizableResource might be the thing keeping the reference. It appears that any JarFile implementation that override close() will end up with finalizer based cleanup.

I'm really not sure how we can fix this one and also keep the fix for #17796. The only idea I've had so far is to create a new JarFile implementation that doesn't override close().

We'll need to do some experiments.

@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 18, 2020
@philwebb philwebb added this to the 2.2.x milestone Aug 18, 2020
@philwebb philwebb self-assigned this Aug 18, 2020
@philwebb philwebb changed the title Memory leak after upgrade from 2.2.6 to 2.2.7 Memory leak in JarFile class after upgrade from 2.2.6 to 2.2.7 Aug 18, 2020
@philwebb philwebb changed the title Memory leak in JarFile class after upgrade from 2.2.6 to 2.2.7 JarFile can cause memory issues when running on Java 11+ Aug 18, 2020
@philwebb philwebb modified the milestones: 2.2.x, 2.2.10 Aug 18, 2020
@philwebb
Copy link
Member

@alexey-anufriev I think I may have a fix for this, but I'm not 100% confident. If you get the chance, could you please try 2.2.10.BUILD-SNAPSHOT and let me know if you still see the issue?

@alexey-anufriev
Copy link
Author

@philwebb, I have already tried the same app with 2.2.10.BUILD-SNAPSHOT and it looks much better. There is a number of wrappers in the heap, but I do not think it will cause problems.

In any case, thank you for the resolution, and I will keep you updated after I get this version live (but it will take me some time).

philwebb added a commit that referenced this issue Aug 18, 2020
Refine method visibility in an attempt to fix test issues on Java 11+.

See gh-22991
philwebb added a commit that referenced this issue Aug 18, 2020
Remove Mockto from JarFileWrapperTests since it seems to be failing on
later versions of Java.

See gh-22991
philwebb added a commit that referenced this issue Aug 19, 2020
Update `JarFileWrapperTests` so that the jar files are closed after each
test.

See gh-22991
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants