Skip to content

Race condition when inbound message handling fails and StompSubProtocolHandler sends ERROR frame [SPR-13326] #17911

Closed
@spring-projects-issues

Description

@spring-projects-issues

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.

@Override
protected void sendTextMessage(TextMessage message) throws IOException {
    Session nativeSession = getNativeSession();
    synchronized (nativeSession) {
        nativeSession.getBasicRemote().sendText(message.getPayload(), message.isLast());
    }
}

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

Metadata

Metadata

Assignees

Labels

status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions