Affects: 5.3.15
For a Spring Boot project with many tests loading the Spring context (@SpringBootTest
): if loading the Spring context fails, the context will remain in memory and test execution will eventually fail with OutOfMemoryError
(hiding the original problem).
I created a heap dump of a failed run. I see 109 instances of org.springframework.beans.factory.support.DefaultListableBeanFactory
on the heap. I see these paths to GC roots preventing the context from being garbage collected:
The context should be closed, when it fails loading. At least for tests.
Comment From: sbrannen
Potentially related to:
-
26266
Comment From: sbrannen
The context should be closed, when it fails loading. At least for tests.
If an ApplicationContext
fails to load (i.e., complete the "refresh" action), it cannot be closed because it was never fully started/refreshed. In addition, I do not believe that the Spring TestContext Framework retains a reference to any ApplicationContext
that failed to start. Though, it may be the case that things are different when using Spring Boot's testing support -- for example, I noticed SpringApplicationShutdownHook
in your screenshot.
Can you please expound on what you mean by "fails loading"?
Also, please provide a sample application that demonstrates the issue you are encountering -- preferably as a Git repo or Zip file that we can download and run.
Stack traces for the failure scenarios would also be useful so that we can better see where things are going wrong.
Comment From: ewirch
Though, it may be the case that things are different when using Spring Boot's testing support
@sbrannen, you were right, Spring Boot's SpringApplicationShutdownHook
is necessary to trigger the problem. I created an issue over there: https://github.com/spring-projects/spring-boot/issues/29874.
Comment From: sbrannen
@sbrannen, you were right, Spring Boot's
SpringApplicationShutdownHook
is necessary to trigger the problem. I created an issue over there: spring-projects/spring-boot#29874.
Thanks!