-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
Suspected memory leak in SpringApplicationShutdownHook during spring boot testsuite execution #37129
Comments
@bclozel I can see that the ApplicationContext is registered with the shutdown hook in |
@Mobe91 Can you please provide a minimal sample that reproduces the leak? |
@wilkinsona I could try but I think it would take quite some effort. Do you think it would make sense for you to first look at the dump? Maybe you spot something quickly that I couldn't... |
We could try that, but from what you've described about the heap dump, it doesn't sound like it's going to help as it isn't showing what's preventing GC of the closed contexts. Another workaround that you could try would be to run your tests with |
I've tried this and it seems to shift the issue to I guess I'll start constructing a fresh spring boot application and try to re-produce this somehow then. Of course, grateful for any tips or hints. |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
I am closing this issue for now since I currently don't have time to create a reproducer. I will reopen or reply if I either have a reproducer or found the root cause of my issue. |
Thanks, @Mobe91. Please do let us know if you manage to make some progress. |
@awhig That seems to be unrelated to this issue which was specifically about test suite execution. FWIW, a |
Spring Boot version: 3.1.2
Java version: 17.0.3, vendor: Eclipse Adoptium
Executing a spring-boot testsuite a
java.lang.OutOfMemoryError
is thrown after some time.The testsuite is executed via maven-surefire-plugin:
The test context caching has been limited to 1 by creating a
spring.properties
file with the following content:spring.test.context.cache.maxSize=1
It has been verified that above setting takes effect by enabling DEBUG logging for
org.springframework.test.context.cache
.From the above setup I would expect that only the last used application context is cached and all other application contexts become eligible for garbage collection.
However, when examining the heap dump that is created when the
java.lang.OutOfMemoryError
is thrown (compare-XX:+HeapDumpOnOutOfMemoryError
setting above) I see thatSpringApplicationShutdownHook#closedContexts
contains 36 entries retaining around 1.6 GB of heap space. When analyzing the path to GC roots using Eclipse MAT for the application contexts contained in this Map then the only path to a GC root goes through theWeakHashMap$Entry
holding the respective application context. When instructing Eclipse MAT to show paths to GC roots excluding weak references no paths are output.Given that a full GC should happen before a
java.lang.OutOfMemoryError
is thrown it seems like something is blocking the GC of application contexts inSpringApplicationShutdownHook#closedContexts
.I can probably provide the heap dump if required (would need to check, though).
The text was updated successfully, but these errors were encountered: