summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-11-23 16:24:44 +0200
committerVaadin Code Review <review@vaadin.com>2012-11-23 15:18:16 +0000
commit7ac88911a373d76b2d4de9edeb3184b5ba15e9d5 (patch)
treecf62c830a7ed238f85e10419cbfc0cf2c60d08d3
parent308d0451d5f98e207ff9d031da014304e422894d (diff)
downloadvaadin-framework-7ac88911a373d76b2d4de9edeb3184b5ba15e9d5.tar.gz
vaadin-framework-7ac88911a373d76b2d4de9edeb3184b5ba15e9d5.zip
Ensure only one sass compilation takes place at a time (#10293)
Change-Id: I782c754d16ffd4f80f81fad0aca18836910bdc50
-rw-r--r--server/src/com/vaadin/server/VaadinServlet.java78
1 files changed, 44 insertions, 34 deletions
diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java
index 9b2eba04db..a285c327eb 100644
--- a/server/src/com/vaadin/server/VaadinServlet.java
+++ b/server/src/com/vaadin/server/VaadinServlet.java
@@ -611,6 +611,13 @@ public class VaadinServlet extends HttpServlet implements Constants {
';' }));
/**
+ * Mutex for preventing to scss compilations to take place simultaneously.
+ * This is a workaround needed as the scss compiler currently is not thread
+ * safe (#10292).
+ */
+ private static final Object SCSS_MUTEX = new Object();
+
+ /**
* Returns the default theme. Must never return null.
*
* @return
@@ -924,44 +931,47 @@ public class VaadinServlet extends HttpServlet implements Constants {
// Handled, return true so no further processing is done
return true;
}
- String realFilename = sc.getRealPath(scssFilename);
- ScssStylesheet scss = ScssStylesheet.get(realFilename);
- if (scss == null) {
- // Not a file in the file system (WebContent directory). Use the
- // identifier directly (VAADIN/themes/.../styles.css) so
- // ScssStylesheet will try using the class loader.
- if (scssFilename.startsWith("/")) {
- scssFilename = scssFilename.substring(1);
- }
+ synchronized (SCSS_MUTEX) {
+ String realFilename = sc.getRealPath(scssFilename);
+ ScssStylesheet scss = ScssStylesheet.get(realFilename);
+ if (scss == null) {
+ // Not a file in the file system (WebContent directory). Use the
+ // identifier directly (VAADIN/themes/.../styles.css) so
+ // ScssStylesheet will try using the class loader.
+ if (scssFilename.startsWith("/")) {
+ scssFilename = scssFilename.substring(1);
+ }
- scss = ScssStylesheet.get(scssFilename);
- }
+ scss = ScssStylesheet.get(scssFilename);
+ }
- if (scss == null) {
- getLogger()
- .warning(
- "Scss file "
- + scssFilename
- + " exists but ScssStylesheet was not able to find it");
- return false;
- }
- try {
- getLogger()
- .fine("Compiling " + realFilename + " for request to "
- + filename);
- scss.compile();
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
+ if (scss == null) {
+ getLogger()
+ .warning(
+ "Scss file "
+ + scssFilename
+ + " exists but ScssStylesheet was not able to find it");
+ return false;
+ }
+ try {
+ getLogger().fine(
+ "Compiling " + realFilename + " for request to "
+ + filename);
+ scss.compile();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
- // This is for development mode only so instruct the browser to never
- // cache it
- response.setHeader("Cache-Control", "no-cache");
- final String mimetype = getService().getMimeType(filename);
- writeResponse(response, mimetype, scss.toString());
+ // This is for development mode only so instruct the browser to
+ // never
+ // cache it
+ response.setHeader("Cache-Control", "no-cache");
+ final String mimetype = getService().getMimeType(filename);
+ writeResponse(response, mimetype, scss.toString());
- return true;
+ return true;
+ }
}
/**