Fix synchronization issue in StompSubProtocolHandler
Two concurrent threads should not send a message on a single WebSocket session at the same time, for example see: http://docs.oracle.com/javaee/7/api/javax/websocket/RemoteEndpoint.Basic.html In StompSubProtocolHandler it is quite possible that multiple messages may be broadcast to a single WebSocket client concurrently. This change adds synchronization around the sending of a message to a specific cilent session. Issue: SPR-11023
This commit is contained in:
parent
a31ac882c5
commit
e764c8d897
|
@ -174,8 +174,12 @@ public class StompSubProtocolHandler implements SubProtocolHandler {
|
|||
try {
|
||||
message = MessageBuilder.withPayload(message.getPayload()).setHeaders(headers).build();
|
||||
byte[] bytes = this.stompEncoder.encode((Message<byte[]>) message);
|
||||
|
||||
synchronized(session) {
|
||||
session.sendMessage(new TextMessage(new String(bytes, Charset.forName("UTF-8"))));
|
||||
}
|
||||
|
||||
}
|
||||
catch (Throwable t) {
|
||||
sendErrorMessage(session, t);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue