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

Failed application contexts are not deregistered from SpringApplicationShutdownHook #29874

Closed
ewirch opened this issue Feb 16, 2022 · 0 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@ewirch
Copy link

ewirch commented Feb 16, 2022

Spring Boot: 2.6.3

Assume a mid sized Gradle project having around 4000 classes, and using integration tests (@SpringBootTest).

If there is a bean wiring issue (a bean referenced, but not declared), loading Spring context for integration tests will fail ("No qualifying bean of type ... available"). Gradle will run all tests by default, even if there are test failures. Assuming enough test cases, test execution will fail with an java.lang.OutOfMemoryError: Java heap space. This is really confusing, when looking at build output of a failed CI build (one usually checks the last lines of output).

Why is test execution running out of heap? GC cannot garbage collect failed application context. Path to GC root is:

thread "SpringApplicationShutdownHook" > SpringApplicationShutdownHook class instance > contexts

The context (GenericWebApplicationContext) contains a resourceCaches field, which contains all classes found for Spring context. This is why it needs a mid sized project to trigger the problem after a reasonable amount of tests.

Find a sample project which triggers the behavior attached. The test project fails after 17 tests. Run

./gradlew test

test-project.zip

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 16, 2022
@bclozel bclozel self-assigned this Feb 18, 2022
@bclozel bclozel added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 18, 2022
@bclozel bclozel added this to the 2.5.x milestone Feb 18, 2022
@bclozel bclozel changed the title spring-boot-test: Spring Boot application integration tests fail with OutOfMemoryError, when application context loading fails Failed application contexts are not unregistered from SpringApplicationShutdownHook Feb 18, 2022
@bclozel bclozel changed the title Failed application contexts are not unregistered from SpringApplicationShutdownHook Failed application contexts are not deregistered from SpringApplicationShutdownHook Feb 18, 2022
@bclozel bclozel modified the milestones: 2.5.x, 2.5.10 Feb 18, 2022
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