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

Spring Boot should release test contexts which failed to load #28021

Closed
ewirch opened this issue Feb 9, 2022 · 4 comments
Closed

Spring Boot should release test contexts which failed to load #28021

ewirch opened this issue Feb 9, 2022 · 4 comments
Assignees
Labels
for: external-project Needs a fix in external project

Comments

@ewirch
Copy link

ewirch commented Feb 9, 2022

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:
image

The context should be closed, when it fails loading. At least for tests.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 9, 2022
@sbrannen sbrannen added the in: test Issues in the test module label Feb 9, 2022
@sbrannen sbrannen self-assigned this Feb 9, 2022
@sbrannen sbrannen modified the milestones: 5.3.16, Triage Queue Feb 9, 2022
@sbrannen sbrannen added the status: waiting-for-feedback We need additional information before we can continue label Feb 11, 2022
@sbrannen sbrannen removed their assignment Feb 11, 2022
@sbrannen sbrannen removed the in: test Issues in the test module label Feb 11, 2022
@sbrannen
Copy link
Member

Potentially related to:

@sbrannen
Copy link
Member

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.

@ewirch
Copy link
Author

ewirch commented Feb 16, 2022

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: spring-projects/spring-boot#29874.

@ewirch ewirch closed this as completed Feb 16, 2022
@sbrannen
Copy link
Member

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

@sbrannen sbrannen removed this from the Triage Queue milestone Feb 16, 2022
@sbrannen sbrannen self-assigned this Feb 16, 2022
@sbrannen sbrannen added for: external-project Needs a fix in external project and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 16, 2022
@sbrannen sbrannen changed the title Spring Test should unload contexts which failed loading (avoid OutOfMemoryError) Spring Boot should release test contexts which failed to load Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project Needs a fix in external project
Projects
None yet
Development

No branches or pull requests

3 participants