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.

Issue: SPR-11916
This commit is contained in:
Rossen Stoyanchev 2014-07-02 13:47:48 -04:00
parent 5614e257d1
commit 59e02e63c4
1 changed files with 15 additions and 13 deletions

View File

@ -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);
} }
} }
@ -244,8 +246,8 @@ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
* @param response the current response * @param response the current response
* @param frameFormat the transport-specific SocksJS frame format to use * @param frameFormat the transport-specific SocksJS frame format to use
*/ */
public void handleSuccessiveRequest(ServerHttpRequest request, public void handleSuccessiveRequest(ServerHttpRequest request, ServerHttpResponse response,
ServerHttpResponse response, SockJsFrameFormat frameFormat) throws SockJsException { SockJsFrameFormat frameFormat) throws SockJsException {
synchronized (this.responseLock) { synchronized (this.responseLock) {
try { try {