Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51340
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 8 Jun 2011 15:52:26 +0000 (15:52 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 8 Jun 2011 15:52:26 +0000 (15:52 +0000)
Fix thread-safety issue when parsing multiple web.xml files in parallel. Apache Tomcat does not do this but products that embed it may.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1133446 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/startup/ContextConfig.java
webapps/docs/changelog.xml

index adecb5f..ac396c9 100644 (file)
@@ -1676,13 +1676,18 @@ public class ContextConfig
         // thread safe. Whilst there should only be one thread at a time
         // processing a config, play safe and sync.
         Digester digester;
+        WebRuleSet ruleSet;
         if (fragment) {
             digester = webFragmentDigester;
+            ruleSet = webFragmentRuleSet;
         } else {
             digester = webDigester;
+            ruleSet = webRuleSet;
         }
         
-        synchronized(digester) {
+        // Sync on the ruleSet since the same ruleSet is shared across all four
+        // digesters
+        synchronized(ruleSet) {
             
             digester.push(dest);
             digester.setErrorHandler(handler);
@@ -1713,11 +1718,7 @@ public class ContextConfig
                 ok = false;
             } finally {
                 digester.reset();
-                if (fragment) {
-                    webFragmentRuleSet.recycle();
-                } else {
-                    webRuleSet.recycle();
-                }
+                ruleSet.recycle();
             }
         }
     }
index 34374e6..b42f0bc 100644 (file)
         Avoid possible NPE when logging requests received during embedded Tomcat
         shutdown. (markt)
       </fix>
+      <fix>
+        <bug>51340</bug>: Fix thread-safety issue when parsing multiple web.xml
+        files in parallel. Apache Tomcat does not do this but products that
+        embed it may. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">