-
Notifications
You must be signed in to change notification settings - Fork 38.2k
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
Change default phase for STOMP message handling components to be ahead of Boot's WebServerStartStopLifecycle default phase #27519
Comments
Does the problem occur without sockjs? |
Can you please move that code in text in a small sample that we can run ourselves. I want to make sure that we're not missing anything. Also, answering the question above would be nice to help us track down where that would come from. |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
This comment was marked as off-topic.
This comment was marked as off-topic.
@snicoll @trylimits After testing, spring boot is fine.Only the web connection needs to be wrapped in SockJS
|
I replicated the issue by using the Spring WebSocket example. This example does not use SockJS and the behavior is still reproducible.
Screenshot of Chrome Dev Tools showing that the server did not respond: This behavior is relevant in the following real-world scenario:
We can reproduce that real-world example by simulating 10k clients and restart the backend service. About 10% of the clients face that issue. |
So this looks like a race condition between the time when the server starts accepting connections and the time when it is actually able to properly respond to those connections ( |
Reviewing this with @rstoyanchev, this turns out to be a lifecycle misalignment where the startup of the message broker happens after the startup of the embedded server in Spring boot, leaving some room for mishandling early connections inbetween. We intend to make the lifecycle phase configurable in |
Indeed, That said I see something in the logs that I can't explain:
The "Starting..." log message is on a thread other than In any case, as @jhoeller pointed out we intend to make the phase configurable in 6.1.x with #32205, and will also consider changes to the default for 6.2. |
The original log output comes from an application running on Spring v5.3.3. This might explain the discrepancy. Since the issue can also be reproduced with the Spring example, perhaps the following log output might be of more interest:
|
As I explained already, there is an issue with phase ordering and we plan to address that. However, it's possible that typically doesn't make enough of a difference, and there may be something more going on. Those log messages have been there since 2014, and the first one appearing on a different thread is what caught my eye. |
@zxuanhong Had to comment to thank you for the suggestion to wrap the client in a SockJS connection! I've had an old project that was based on the websocket Spring project here and it's been broken for over a year with dependency drift. All fixed now (mostly) thanks to you though, appreciate it! |
Affects: >=5.3.3
Consider a Spring Boot application with the following websocket configuration class:
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 aCONNECTED
response from the server.Precisely, the behavior is as follows:
/info
REST endpoint (SockJS protocol) is available and responds correctly.ws://.../server/.../websocket
is available.o
is sent from the server just after the websocket connection is established.["CONNECT\naccept-version:1.1,1.0\nheart-beat:10000,10000\n\n\u0000"]
.h
.Screenshot:
Relevant log output during startup:
The log output of
WebSocketMessageBrokerStats
shows three connections already before theSimpleBrokerMessageHandler
is starting, respectivelySubProtocolWebSocketHandler#start()
has been called.After
SubProtocolWebSocketHandler#start()
has been called, the server responds correctly.The text was updated successfully, but these errors were encountered: