Skip to content

Change default phase for STOMP message handling components to be ahead of Boot's WebServerStartStopLifecycle default phase #27519

Closed
@trylimits

Description

@trylimits

Affects: >=5.3.3


Consider a Spring Boot application with the following websocket configuration class:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

	@Override
	public void configureMessageBroker(MessageBrokerRegistry config) {
		config.setApplicationDestinationPrefixes("/app");
		config.enableSimpleBroker("/topic", "/queue");
		config.setUserDestinationPrefix("/user");
	}

	@Override
	public void registerStompEndpoints(StompEndpointRegistry registry) {
		String[] cors= new String[] { "*" };
		registry.addEndpoint("/server").setAllowedOriginPatterns(cors).withSockJS();
	}

}

This configuration creates a STOMP endpoint /server over SockJS.
During startup, we observe a short time window, in which clients are able to connect to that endpoint (CONNECT message), without receiving a CONNECTED response from the server.
Precisely, the behavior is as follows:

  1. The /info REST endpoint (SockJS protocol) is available and responds correctly.
  2. The websocket over ws://.../server/.../websocket is available.
  3. The initial message o is sent from the server just after the websocket connection is established.
  4. The client sends the message ["CONNECT\naccept-version:1.1,1.0\nheart-beat:10000,10000\n\n\u0000"].
  5. The server does not respond to that message, however, it sends periodical heartbeat messages h.
  6. The client (JS frontend library) resides in a not-connected state without trying to reconnect.

Screenshot:
image

Relevant log output during startup:

2021-10-05 15:13:13.796  INFO 21428 --- [           main] o.s.b.w.e.t.TomcatWebServer              : Tomcat started on port(s): 8080 (http) with context path ''
[...]
2021-10-05 15:14:09.160  INFO 21428 --- [MessageBroker-4] o.s.w.s.c.WebSocketMessageBrokerStats    : WebSocketSession[3 current WS(3)-HttpStream(0)-HttpPoll(0), 3 total, 0 closed abnormally (0 connect failure, 0 send limit, 0 transport error)], stompSubProtocol[processed CONNECT(3)-CONNECTED(0)-DISCONNECT(0)], stompBrokerRelay[null], inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], outboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], sockJsScheduler[pool size = 8, active threads = 1, queued tasks = 4, completed tasks = 5]
[...]
2021-10-05 15:14:11.355 DEBUG 21428 --- [pool-4-thread-1] o.s.m.s.b.SimpleBrokerMessageHandler     : Starting...
2021-10-05 15:14:17.349  INFO 21428 --- [           main] o.s.m.s.b.SimpleBrokerMessageHandler     : BrokerAvailabilityEvent[available=true, SimpleBrokerMessageHandler [org.springframework.messaging.simp.broker.DefaultSubscriptionRegistry@134a27c1]]
2021-10-05 15:14:17.350  INFO 21428 --- [           main] o.s.m.s.b.SimpleBrokerMessageHandler     : Started.

The log output of WebSocketMessageBrokerStats shows three connections already before the SimpleBrokerMessageHandler is starting, respectively SubProtocolWebSocketHandler#start() has been called.

After SubProtocolWebSocketHandler#start() has been called, the server responds correctly.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: feedback-providedFeedback has been providedtype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions