tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r672397 - /tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java
Date Fri, 27 Jun 2008 21:39:27 GMT
Author: markt
Date: Fri Jun 27 14:39:27 2008
New Revision: 672397

URL: http://svn.apache.org/viewvc?rev=672397&view=rev
Log:
Fix for part 3 of https://issues.apache.org/bugzilla/show_bug.cgi?id=43683
This isn't perfect but it narrows the window for the race condition significantly. A perfect
fix would require syncing most (all?) of allocate() which is on the critical path.

Modified:
    tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java?rev=672397&r1=672396&r2=672397&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java Fri Jun 27 14:39:27 2008
@@ -766,6 +766,8 @@
             throw new ServletException
               (sm.getString("standardWrapper.unloading", getName()));
 
+        boolean newInstance = false;
+        
         // If not SingleThreadedModel, return the same instance every time
         if (!singleThreadModel) {
 
@@ -778,6 +780,12 @@
                                 log.debug("Allocating non-STM instance");
 
                             instance = loadServlet();
+                            // For non-STM, increment here to prevent a race
+                            // condition with unload. Bug 43683, test case #3
+                            if (!singleThreadModel) {
+                                newInstance = true;
+                                countAllocated++;
+                            }
                         } catch (ServletException e) {
                             throw e;
                         } catch (Throwable e) {
@@ -791,10 +799,13 @@
             if (!singleThreadModel) {
                 if (log.isTraceEnabled())
                     log.trace("  Returning non-STM instance");
-                countAllocated++;
+                // For new instances, count will have been incremented at the
+                // time of creation
+                if (!newInstance) {
+                    countAllocated++;
+                }
                 return (instance);
             }
-
         }
 
         synchronized (instancePool) {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message