Skip to content

StompBrokerRelayMessageHandler exception on restart due to test context pause #36266

@spadou

Description

@spadou

Using Spring Boot 4.0.2.

The newly introduced feature for test contexts pause is causing an issue with StompBrokerRelayMessageHandler. It implements SmartLifecycle and will be stopped then restarted when the context change in the test context cache, unfortunately it doesn't support restating so the following exception is thrown on restart.

java.lang.IllegalStateException: Shutting down.
	at org.springframework.messaging.tcp.reactor.ReactorNettyTcpClient.handleShuttingDownConnectFailure(ReactorNettyTcpClient.java:232) ~[spring-messaging-7.0.3.jar:7.0.3]
	at org.springframework.messaging.tcp.reactor.ReactorNettyTcpClient.connectAsync(ReactorNettyTcpClient.java:208) ~[spring-messaging-7.0.3.jar:7.0.3]
	at org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler.startInternal(StompBrokerRelayMessageHandler.java:447) ~[spring-messaging-7.0.3.jar:7.0.3]
	at org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler.start(AbstractBrokerMessageHandler.java:224) ~[spring-messaging-7.0.3.jar:7.0.3]
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:420) ~[spring-context-7.0.3.jar:7.0.3]
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:409) ~[spring-context-7.0.3.jar:7.0.3]
	at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:613) ~[spring-context-7.0.3.jar:7.0.3]
	at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]

The ReactorNettyTcpClient used by StompBrokerRelayMessageHandler has a stopping flag that is set on the initial stop and prevent restarting it.

Not sure if StompBrokerRelayMessageHandler should just be marked as not pausable or if it can be upgraded to support restart.

The attached project can be used to reproduce the issue by running the test class: reprostompbrokerpause.zip. It create two separate contexts and switch between them, causing the last test to fail when it try to restart the paused StompBrokerRelayMessageHandler from the first context. Setting spring.test.context.cache.pause=never in spring.properties to prevent pausing test contexts will allow the tests to run successfully.

Also, probably not related to this issue, but the attached project can be used to reproduce the issue mentioned in #32672. Just starting then stopping the application class will throw the mentioned exception when the StompBrokerRelayMessageHandler is stopping.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions