Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

WebSocketMessageBrokerStats has null stats for stompSubProtocolHandler since 5.3.2 #26536

Closed
countableSet opened this issue Feb 10, 2021 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@countableSet
Copy link

Since upgrading spring-websockets library to version 5.3.2 I've noticed the WebSocketMessageBrokerStats class no longer provides metrics for stompSubProtocolHandler. I think I've traced it down to different bean creation order between two library versions, in which the webSocketMessageBrokerStats bean is constructed before the stompWebSocketHandlerMapping which adds a stompSubProtocolHandler from adding a stomp endpoint.


A quick summary of the difference:

Broken since Spring Boot 2.4.1 with websocket 5.3.2
Here's the call order I'm seeing in the new version:

  1. Bean constructed: WebSocketMessageBrokerConfigurationSupport#subProtocolWebSocketHandler
  2. Bean constructed: WebSocketMessageBrokerConfigurationSupport#webSocketMessageBrokerStats
    • subProtocolWebSocketHandler bean at this stage has no protocolHandlers and no defaultProtocolHandler
    • WebSocketMessageBrokerStats#setSubProtocolWebSocketHandler sets stompSubProtocolHandler to null
  3. Bean constructed: WebSocketMessageBrokerConfigurationSupport#stompWebSocketHandlerMapping
    • calls WebSocketMessageBrokerConfigurationSupport#registerStompEndpoints
    • registry.addEndpoint(...) adds one protocolHandler to webSocketHandler
  4. When trying to access WebSocketMessageBrokerStats#getStompSubProtocolStatsInfo "null" string is returned.

Was working in Spring Boot 2.4.0 with websocket 5.3.1
Call chain for the 'working' version where webSocketMessageBrokerStats.stompSubProtocolStatsInfo doesn't return null.

  1. Bean constructed: WebSocketMessageBrokerConfigurationSupport#subProtocolWebSocketHandler
  2. Bean constructed: WebSocketMessageBrokerConfigurationSupport#stompWebSocketHandlerMapping
    • calls WebSocketMessageBrokerConfigurationSupport#registerStompEndpoints
    • registry.addEndpoint(...) adds one protocolHandler to webSocketHandler
  3. Bean constructed: WebSocketMessageBrokerConfigurationSupport#webSocketMessageBrokerStats
    • subProtocolWebSocketHandler bean at this stage has one protocolHandlers and no defaultProtocolHandler
  4. When trying to access WebSocketMessageBrokerStats#getStompSubProtocolStatsInfo processed CONNECT(0)-CONNECTED(0)-DISCONNECT(0) string is returned, which is expected.

I also created a demo app for the issue here https://github.com/countableSet/spring-websocket-metrics-bug-demo
Just flip between spring boot versions 2.4.0 and 2.4.1 you should be able to see the issue in std.out.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 10, 2021
@rstoyanchev rstoyanchev added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Nov 10, 2021
@rstoyanchev rstoyanchev self-assigned this Nov 21, 2023
@rstoyanchev
Copy link
Contributor

Thanks for the sample project. I am able to reproduce the issue. I'll experiment with changing WebSocketBrokerStats to an InitializingBean in order to defer its initialization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants