Correct deadlock introduced in r1142112
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 2 Jul 2011 11:29:46 +0000 (11:29 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 2 Jul 2011 11:29:46 +0000 (11:29 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1142205 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/core/StandardWrapper.java

index a2c85aa..2d8d15e 100644 (file)
@@ -822,13 +822,7 @@ public class StandardWrapper extends ContainerBase
                                 log.debug("Allocating non-STM instance");
 
                             instance = loadServlet();
-                            if (singleThreadModel) {
-                                // No need to lock pool since until an instance
-                                // is created, no threads will get past this
-                                // point
-                                instancePool.push(instance);
-                                nInstances++;
-                            } else {
+                            if (!singleThreadModel) {
                                 // For non-STM, increment here to prevent a race
                                 // condition with unload. Bug 43683, test case
                                 // #3
@@ -850,7 +844,14 @@ public class StandardWrapper extends ContainerBase
                 initServlet(instance);
             }
 
-            if (!singleThreadModel) {
+            if (singleThreadModel) {
+                // Have to do this outside of the sync above to prevent a
+                // possible deadlock
+                synchronized (instancePool) {
+                    instancePool.push(instance);
+                    nInstances++;
+                }
+            } else {
                 if (log.isTraceEnabled())
                     log.trace("  Returning non-STM instance");
                 // For new instances, count will have been incremented at the