Skip to content

@RestartScope can cause 'Recursive update' exceptions when used with container beans #41571

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
piotrooo opened this issue Jul 22, 2024 · 3 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@piotrooo
Copy link

piotrooo commented Jul 22, 2024

After updating Spring Boot from 3.3.1 to 3.3.2, I receive an exception with the following configuration:

@TestConfiguration(proxyBeanMethods = false)
public class ContainersConfiguration {

    @Bean
    @ServiceConnection
    @RestartScope
    PostgreSQLContainer<?> postgresContainer() {
        return new PostgreSQLContainer<>("postgres:16");
    }

    @Bean
    @ServiceConnection
    @RestartScope
    RabbitMQContainer rabbitContainer() {
        try (RabbitMQContainer rabbitMQContainer = new RabbitMQContainer("rabbitmq:3.13")) {
            return rabbitMQContainer
                    .withExposedPorts(5672, 15672);
        }
    }

}

Exception:

Caused by: org.springframework.beans.factory.support.ScopeNotActiveException: Error creating bean with name 'rabbitContainer': Scope 'restart' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:385)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
	at org.springframework.boot.testcontainers.lifecycle.TestcontainersLifecycleBeanPostProcessor.getBeans(TestcontainersLifecycleBeanPostProcessor.java:154)
	at org.springframework.boot.testcontainers.lifecycle.TestcontainersLifecycleBeanPostProcessor.initializeStartables(TestcontainersLifecycleBeanPostProcessor.java:107)
	at org.springframework.boot.testcontainers.lifecycle.TestcontainersLifecycleBeanPostProcessor.postProcessAfterInitialization(TestcontainersLifecycleBeanPostProcessor.java:93)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:438)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1809)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:600)
	... 66 more
Caused by: java.lang.IllegalStateException: Recursive update
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1763)
	at org.springframework.boot.devtools.restart.Restarter.getOrAddAttribute(Restarter.java:443)
	at org.springframework.boot.devtools.restart.RestartScopeInitializer$RestartScope.get(RestartScopeInitializer.java:44)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:373)
	... 73 more

When I remove the @RestartScope from the rabbitContainer bean, everything works as expected. It seems to be related to issue #41238.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 22, 2024
@wilkinsona
Copy link
Member

#41552, which describes a problem with @RestartScope and DynamicPropertyRegistry, may also be related.

@eddumelendez
Copy link
Contributor

@piotrooo Can you share a project that reproduces the issue, please? I tried with one of my examples but couldn't reproduce it.

@piotrooo
Copy link
Author

Can you share a project that reproduces the issue, please?

@eddumelendez yes! Sure, I even saw you tweet about it recently 😉

Here is a minimal repro: https://github.com/piotrooo/spring-boot-restart-scope
You just need to run DemoApplicationTests.

@philwebb philwebb changed the title Cannot create RabbitMQContainer with @RestartScope annotation @RestartScope can cause 'Recursive update' exceptions when used with container beans Sep 3, 2024
@philwebb philwebb added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 3, 2024
@philwebb philwebb added this to the 3.2.x milestone Sep 3, 2024
@philwebb philwebb self-assigned this Sep 3, 2024
@philwebb philwebb modified the milestones: 3.2.x, 3.2.10 Sep 3, 2024
@philwebb philwebb added type: bug A general bug and removed type: regression A regression from a previous release labels Sep 3, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants