-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
Using Spring Boot 4.0.2.
The newly introduced feature for test context pausing is causing an issue with StompBrokerRelayMessageHandler. It implements SmartLifecycle and will be stopped and then restarted when the context changes in the test context cache. Unfortunately it doesn't support restarting, 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 prevents restarting it.
Not sure if StompBrokerRelayMessageHandler should just be marked as not pauseable 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 creates two separate contexts and switches between them, causing the last test to fail when it tries 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 and then stopping the application class will throw the mentioned exception when the StompBrokerRelayMessageHandler is stopping.