-
Notifications
You must be signed in to change notification settings - Fork 37.7k
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
Messages arriving out-of-order despite setPreservePublishOrder(true) #27173
Comments
Hitting this exact problem with a simple controller which just sends values 0,1,2,... First I added receipts according to #21848 (comment) Then the out of order messages remain. I have a single client and the magic seems to be to reduce the number of broker-channel threads to 2. I implemented WebSocketMessageBrokerConfigurer.configureMessageBroker and added the line registry.configureBrokerChannel().taskExecutor().corePoolSize(2).maxPoolSize(2) It will hit the problem 100% of the time. reducing the number of threads to 1 (core/max) gets rid of the problem. Since I am unfamiliar with the code I have not been able to pinpoint the problem yet, but I suspect SendTask's are sent to the threadpool and the order of execution is not determined. |
It seems the UserDestinationMessageHandler.handleMessage calls ExecutorSubscribableChannel.sendInternal, which just passes a SendTask to the executor (ThreadPoolTaskExecutor). The order of execution of the tasks passed to the threadpool is undefined. It also explains why limiting the number of threads in the brokerChannel works around the problem. Summary: message order is not preserved with user destinations. This callstack is from the broker-channel. sendInternal:103, ExecutorSubscribableChannel (org.springframework.messaging.support) |
Like @osharaki I ended up implementing message ordering on the application level. Basically a striped executor installed on the clientOutboundChannel. I use the (sessionId, destination) as the stripe-key and a native header with the message sequence number. I still think the race condition is a bug and needs fixing. The order preservation is a clear issue with user specific queues. |
Faced with the same issue. @p4654545 sorry, but from my understanding @rstoyanchev could you please shed some light on this? |
OrderedMessageChannelDecorator has a race condition when there are messages sent on the outboundchannel without using the decorator. |
Greetings! Is there any update on this? |
That said, @azhuchkov I think you're right that messages sent from We have #21798 scheduled to apply the same decorator to the I will keep this open for now until #21798 is resolved, and we have confirmation it works. |
There is now 6.1.0-SNAPSHOT with the fixes for #21798 and #31395, and 6.1.0-RC1 is due tomorrow. Messages handled in If anyone is able to check that it works in their environment, that would be very helpful. |
setPreservePublishOrder(true)
doesn't seem to guarantee that the client receives messages in the order of publication. I still need to account for server responses arriving out-of-order on the client side by checking for timestamps.I noticed this issue while running integration tests for my STOMP over WebSocket and SockJS server where I would have up to 70
WebSocketStompClient
SockJS clients connect and issue requests in quick succession. Although with a low number of clientssetPreservePublishOrder(true)
does seem to eliminate out-of-order messages, as the number of clients increases, the order is no longer guaranteed and client-side ordering via a response timestamp is needed.The documentation makes no mention of possible shortcomings when the server is overloaded, so I'm assuming this behavior should not be happening.
I'm using version 2.4.5.
The text was updated successfully, but these errors were encountered: