Skip to content

Commit

Permalink
Synchronize request init in AbstractHttpSockJsSession
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rstoyanchev committed Jul 2, 2014
1 parent 5614e25 commit 59e02e6
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,20 @@ public void handleInitialRequest(ServerHttpRequest request, ServerHttpResponse r
this.frameFormat = frameFormat;
this.asyncRequestControl = request.getAsyncRequestControl(response);

try {
// Let "our" handler know before sending the open frame to the remote handler
delegateConnectionEstablished();
writePrelude(request, response);
writeFrame(SockJsFrame.openFrame());
if (isStreaming() && !isClosed()) {
startAsyncRequest();
synchronized (this.responseLock) {
try {
// Let "our" handler know before sending the open frame to the remote handler
delegateConnectionEstablished();
writePrelude(request, response);
writeFrame(SockJsFrame.openFrame());
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);
}
}

Expand Down Expand Up @@ -244,8 +246,8 @@ private void startAsyncRequest() {
* @param response the current response
* @param frameFormat the transport-specific SocksJS frame format to use
*/
public void handleSuccessiveRequest(ServerHttpRequest request,
ServerHttpResponse response, SockJsFrameFormat frameFormat) throws SockJsException {
public void handleSuccessiveRequest(ServerHttpRequest request, ServerHttpResponse response,
SockJsFrameFormat frameFormat) throws SockJsException {

synchronized (this.responseLock) {
try {
Expand Down

0 comments on commit 59e02e6

Please sign in to comment.