Browse Source

Synchronize request init in AbstractHttpSockJsSession

Although unlikely in practice (but not impossible), the SockJS
integration tests write a message while the request is initializing.
This change adds synchronization around request intiailization
for the SockJS HTTP sesion.

This is a backport of:
59e02e63c4

Issue: SPR-11916
pull/618/head
Rossen Stoyanchev 12 years ago
parent
commit
977c5ca439
  1. 24
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractHttpSockJsSession.java

24
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractHttpSockJsSession.java

@ -201,18 +201,20 @@ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
this.frameFormat = frameFormat; this.frameFormat = frameFormat;
this.asyncRequestControl = request.getAsyncRequestControl(response); this.asyncRequestControl = request.getAsyncRequestControl(response);
try { synchronized (this.responseLock) {
// Let "our" handler know before sending the open frame to the remote handler try {
delegateConnectionEstablished(); // Let "our" handler know before sending the open frame to the remote handler
writePrelude(request, response); delegateConnectionEstablished();
writeFrame(SockJsFrame.openFrame()); writePrelude(request, response);
if (isStreaming() && !isClosed()) { writeFrame(SockJsFrame.openFrame());
startAsyncRequest(); if (isStreaming() && !isClosed()) {
startAsyncRequest();
}
}
catch (Throwable ex) {
tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR);
throw new SockJsTransportFailureException("Failed to open session", getId(), ex);
} }
}
catch (Throwable ex) {
tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR);
throw new SockJsTransportFailureException("Failed to open session", getId(), ex);
} }
} }

Loading…
Cancel
Save