-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Race condition when inbound message handling fails and StompSubProtocolHandler sends ERROR frame [SPR-13326] #17911
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
Comments
Rossen Stoyanchev commented What version of Spring Framework are you using and also what server/version? The |
Tong Chen commented I am using spring 4.1.5.RELEASE Stacktrace |
Rossen Stoyanchev commented Oops, looks like we are only passing the concurrent session decorator to SubProtocolHandler for outbound messages and never did so for inbound messages for which we don't typically use the session unless inbound message handling fails and we try to send an ERROR frame to the client. Thanks for reporting! |
Tong Chen commented Thanks Rossen, in the mean time, can you suggest a nicer workaround (rather than the synchronized block I put in)? |
Rossen Stoyanchev commented Since you're already using WebSocketMessageBrokerConfigurationSupport, you could override subProtocolWebSocketHandler and return a SubProtocolWebSocketHandler sub-class overriding |
Chandan commented Is this issue Only with Stomp? I am observing similar issue while using SockJs support -client is sockjs which uses JSON RPC protocol. For some conditions it is resulting in Race Conditions: AbstractHttpSockJsSession acquires a lock while sending message : For this reason, I was not using lock in my handlers. When a synchronised block, it alleviates the issue
I am using 4.1.5 but I am unable to assess the exact cause of race condition. If possible, please confirm if this issue is for HTTP handlers as well -then I can propose a lib upgrade (We use platform so it might be a tedious process and needs concrete validations) |
Andre Gonçalves commented
|
Rossen Stoyanchev commented Are you at the WebSocket/SockJS level, i.e. not using the sub-protocol support? The STOMP support also takes care of sending messages concurrently. If using a WebSocketSession directly you need take care of synchronizing the sends. This shouldn't be too hard however if you wrap the session. See my response under #18029. |
Tong Chen opened SPR-13326 and commented
If for any reason such as some message parsing failed, StompSubProtocolHandler.sendErrorMessage is called and it ultimately calling StandardWebSocketSession.sendTextMessage to send the error msg back to client.
But from that method call I am getting exception:
"The remote endpoint was in state [TEXT_PARTIAL_WRITING] which is an invalid state for called method".
It looks like a race condition because when it is trying to use the native session to send msg back, the native session is also used by other normal messages.
Adding the following work around seems to fixed the problem.
The message calling flow is quite complicated so I may have missed something obvious please let me know if my observation is flawed.
Issue Links:
Referenced from: commits 33f9ead, 7defbfc
Backported to: 4.1.8
The text was updated successfully, but these errors were encountered: