Skip to content

Memory not freed on context restart in JpaMetamodel#CACHE with spring.main.lazy-initialization=true #46630

@joaemel

Description

@joaemel

Upon request, I am re-reporting an bug here, original here: spring-projects/spring-data-jpa#3957

When spring.main.lazy-initialization is true, the LazyInitializationBeanFactoryPostProcessor makes the JpaMetamodelCacheCleanup bean lazy, causing the cleanup to never happen. This manifests in OOMs when running lots of tests with DirtiesContext.

Adding this bean to the context:

    @Bean
    public static LazyInitializationExcludeFilter integrationLazyInitializationExcludeFilter() {
        return (beanName, beanDefinition, beanType)
            -> beanName.equals("org.springframework.data.jpa.util.JpaMetamodelCacheCleanup");
    }

Works around the issue.

This issue was observed in spring boot 3.2.11 and, upon request, I created a minimal reproducing sample project including a failing test, using up-to-date (3.5.4) spring boot:

reproduce.tar.gz

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions