Skip to content

Restarter creates memory leak in tests #37373

@chris-melman

Description

@chris-melman

We run into memory problems on our buildstreet for automated tests.
We are using an abstract base class (removed non spring functionality)

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD) /
public abstract class AbstractEndToEndTest {

    @DynamicPropertySource
    static void registerDynamicProperties(DynamicPropertyRegistry registry) {
        registry.add("spring.datasource.url", () -> POSTGRESS_SQL_CONTAINER.getJdbcUrl());
        registry.add("spring.datasource.username", () -> POSTGRESS_SQL_CONTAINER.getUsername());
        registry.add("spring.datasource.password", () -> POSTGRESS_SQL_CONTAINER.getPassword());
    }

}

After some investigation we found that the org.springframework.boot.devtools.restart.Restarter is adding context to its rootContexts, however they never seems to be cleaned
unnamed (2)
unnamed (4)

private final List<ConfigurableApplicationContext> rootContexts = new CopyOnWriteArrayList<>();

Setting spring.test.context.cache.maxSize didn't help.

The current workaround is that we call the Restarter.clearInstance() after each test. However this is more a workaround. I would expect that the @SpringBootTest would clean this after the test has been run.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions