summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2014-04-02 20:11:43 +0300
committerArtur Signell <artur@vaadin.com>2014-04-02 20:13:52 +0300
commit7f9ea1c9159c8362e6a309b630cbb59a4dae72dd (patch)
treef4a17ba0cb4cc5db0d07bffb26f3ab81f05d9e11 /server
parent8138be4b0352c5b2409b48ad600941afeed3b20b (diff)
downloadvaadin-framework-7f9ea1c9159c8362e6a309b630cbb59a4dae72dd.tar.gz
vaadin-framework-7f9ea1c9159c8362e6a309b630cbb59a4dae72dd.zip
Workaround for Atmosphere race condition (#13528)
Change-Id: I39cb72ef9a1f6c6424dce7f9feff2cebbfe3fdfd
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/server/communication/PushRequestHandler.java72
1 files changed, 40 insertions, 32 deletions
diff --git a/server/src/com/vaadin/server/communication/PushRequestHandler.java b/server/src/com/vaadin/server/communication/PushRequestHandler.java
index 7ac4c0e406..82e3961049 100644
--- a/server/src/com/vaadin/server/communication/PushRequestHandler.java
+++ b/server/src/com/vaadin/server/communication/PushRequestHandler.java
@@ -57,6 +57,12 @@ public class PushRequestHandler implements RequestHandler,
private AtmosphereFramework atmosphere;
private PushHandler pushHandler;
+ /**
+ * Atmosphere 2.x has a race condition when AtmosphereFramework init(config)
+ * is run from two threads at once. See http://dev.vaadin.com/ticket/13528
+ */
+ private static Object atmosphereInitRaceConditionWorkaroundLock = new Object();
+
public PushRequestHandler(VaadinServletService service)
throws ServiceException {
@@ -85,38 +91,40 @@ public class PushRequestHandler implements RequestHandler,
}
});
- pushHandler = new PushHandler(service);
- atmosphere.addAtmosphereHandler("/*", pushHandler.handler);
- atmosphere.addInitParameter(ApplicationConfig.BROADCASTER_CACHE,
- UUIDBroadcasterCache.class.getName());
- atmosphere.addInitParameter(ApplicationConfig.PROPERTY_SESSION_SUPPORT,
- "true");
- atmosphere.addInitParameter(ApplicationConfig.MESSAGE_DELIMITER,
- String.valueOf(PushConstants.MESSAGE_DELIMITER));
-
- final String bufferSize = String
- .valueOf(PushConstants.WEBSOCKET_BUFFER_SIZE);
- atmosphere.addInitParameter(ApplicationConfig.WEBSOCKET_BUFFER_SIZE,
- bufferSize);
- atmosphere.addInitParameter(ApplicationConfig.WEBSOCKET_MAXTEXTSIZE,
- bufferSize);
- atmosphere.addInitParameter(ApplicationConfig.WEBSOCKET_MAXBINARYSIZE,
- bufferSize);
-
- // Disable Atmosphere's message about commercial support
- atmosphere.addInitParameter("org.atmosphere.cpr.showSupportMessage",
- "false");
-
- try {
- atmosphere.init(config);
-
- // Ensure the client-side knows how to split the message stream
- // into individual messages when using certain transports
- AtmosphereInterceptor trackMessageSize = new TrackMessageSizeInterceptor();
- trackMessageSize.configure(atmosphere.getAtmosphereConfig());
- atmosphere.interceptor(trackMessageSize);
- } catch (ServletException e) {
- throw new ServiceException("Atmosphere init failed", e);
+ synchronized (atmosphereInitRaceConditionWorkaroundLock) {
+ pushHandler = new PushHandler(service);
+ atmosphere.addAtmosphereHandler("/*", pushHandler.handler);
+ atmosphere.addInitParameter(ApplicationConfig.BROADCASTER_CACHE,
+ UUIDBroadcasterCache.class.getName());
+ atmosphere.addInitParameter(
+ ApplicationConfig.PROPERTY_SESSION_SUPPORT, "true");
+ atmosphere.addInitParameter(ApplicationConfig.MESSAGE_DELIMITER,
+ String.valueOf(PushConstants.MESSAGE_DELIMITER));
+
+ final String bufferSize = String
+ .valueOf(PushConstants.WEBSOCKET_BUFFER_SIZE);
+ atmosphere.addInitParameter(
+ ApplicationConfig.WEBSOCKET_BUFFER_SIZE, bufferSize);
+ atmosphere.addInitParameter(
+ ApplicationConfig.WEBSOCKET_MAXTEXTSIZE, bufferSize);
+ atmosphere.addInitParameter(
+ ApplicationConfig.WEBSOCKET_MAXBINARYSIZE, bufferSize);
+
+ // Disable Atmosphere's message about commercial support
+ atmosphere.addInitParameter(
+ "org.atmosphere.cpr.showSupportMessage", "false");
+
+ try {
+ atmosphere.init(config);
+
+ // Ensure the client-side knows how to split the message stream
+ // into individual messages when using certain transports
+ AtmosphereInterceptor trackMessageSize = new TrackMessageSizeInterceptor();
+ trackMessageSize.configure(atmosphere.getAtmosphereConfig());
+ atmosphere.interceptor(trackMessageSize);
+ } catch (ServletException e) {
+ throw new ServiceException("Atmosphere init failed", e);
+ }
}
}