You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fh...@apache.org on 2012/05/02 19:12:49 UTC

svn commit: r1333114 - in /tomcat/trunk: java/org/apache/coyote/ java/org/apache/tomcat/util/net/ java/org/apache/tomcat/util/threads/ webapps/docs/ webapps/docs/config/

Author: fhanik
Date: Wed May  2 17:12:48 2012
New Revision: 1333114

URL: http://svn.apache.org/viewvc?rev=1333114&view=rev
Log:
https://issues.apache.org/bugzilla/show_bug.cgi?id=53173
Properly handle count down of maxConnections latch when entering edge cases.


Modified:
    tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java
    tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java
    tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
    tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java
    tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
    tomcat/trunk/java/org/apache/tomcat/util/threads/LimitLatch.java
    tomcat/trunk/webapps/docs/changelog.xml
    tomcat/trunk/webapps/docs/config/ajp.xml
    tomcat/trunk/webapps/docs/config/http.xml

Modified: tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java?rev=1333114&r1=1333113&r2=1333114&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java Wed May  2 17:12:48 2012
@@ -541,6 +541,12 @@ public abstract class AbstractProtocol i
                 SocketStatus status) {
             Processor<S> processor = connections.remove(socket.getSocket());
 
+            if (status == SocketStatus.DISCONNECT && processor == null) {
+                //nothing more to be done endpoint requested a close
+                //and there are no object associated with this connection
+                return SocketState.CLOSED;
+            }
+
             socket.setAsync(false);
 
             try {
@@ -555,7 +561,9 @@ public abstract class AbstractProtocol i
 
                 SocketState state = SocketState.CLOSED;
                 do {
-                    if (processor.isAsync() || state == SocketState.ASYNC_END) {
+                    if (status == SocketStatus.DISCONNECT) {
+                        //do nothing here, just wait for it to get recycled
+                    } else if (processor.isAsync() || state == SocketState.ASYNC_END) {
                         state = processor.asyncDispatch(status);
                     } else if (processor.isComet()) {
                         state = processor.event(status);

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java?rev=1333114&r1=1333113&r2=1333114&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java Wed May  2 17:12:48 2012
@@ -163,7 +163,12 @@ public abstract class AbstractEndpoint {
         LimitLatch latch = this.connectionLimitLatch;
         if (latch != null) {
             // Update the latch that enforces this
+            if (maxCon == -1)
+                releaseConnectionLatch();
+            else
             latch.setLimit(maxCon);
+        } else if (maxCon > 0) {
+            initializeConnectionLatch();
         }
     }
 
@@ -655,6 +660,7 @@ public abstract class AbstractEndpoint {
     public abstract boolean getUsePolling();
 
     protected LimitLatch initializeConnectionLatch() {
+        if (maxConnections==-1) return null;
         if (connectionLimitLatch==null) {
             connectionLimitLatch = new LimitLatch(getMaxConnections());
         }
@@ -668,11 +674,13 @@ public abstract class AbstractEndpoint {
     }
 
     protected void countUpOrAwaitConnection() throws InterruptedException {
+        if (maxConnections==-1) return;
         LimitLatch latch = connectionLimitLatch;
         if (latch!=null) latch.countUpOrAwait();
     }
 
     protected long countDownConnection() {
+        if (maxConnections==-1) return -1;
         LimitLatch latch = connectionLimitLatch;
         if (latch!=null) {
             long result = latch.countDown();

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1333114&r1=1333113&r2=1333114&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Wed May  2 17:12:48 2012
@@ -995,6 +995,8 @@ public class AprEndpoint extends Abstrac
                         // socket
                         socket = Socket.accept(serverSock);
                     } catch (Exception e) {
+                        //we didn't get a socket
+                        countDownConnection();
                         // Introduce delay if necessary
                         errorDelay = handleExceptionWithDelay(errorDelay);
                         // re-throw
@@ -1006,10 +1008,12 @@ public class AprEndpoint extends Abstrac
                     if (running && !paused) {
                         // Hand this socket off to an appropriate processor
                         if (!processSocketWithOptions(socket)) {
+                            countDownConnection();
                             // Close socket and pool right away
                             destroySocket(socket);
                         }
                     } else {
+                        countDownConnection();
                         // Close socket and pool right away
                         destroySocket(socket);
                     }

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java?rev=1333114&r1=1333113&r2=1333114&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java Wed May  2 17:12:48 2012
@@ -216,6 +216,7 @@ public class JIoEndpoint extends Abstrac
                         // socket
                         socket = serverSocketFactory.acceptSocket(serverSocket);
                     } catch (IOException ioe) {
+                        countDownConnection();
                         // Introduce delay if necessary
                         errorDelay = handleExceptionWithDelay(errorDelay);
                         // re-throw
@@ -228,10 +229,12 @@ public class JIoEndpoint extends Abstrac
                     if (running && !paused && setSocketOptions(socket)) {
                         // Hand this socket off to an appropriate processor
                         if (!processSocket(socket)) {
+                            countDownConnection();
                             // Close socket right away
                             closeSocket(socket);
                         }
                     } else {
+                        countDownConnection();
                         // Close socket right away
                         closeSocket(socket);
                     }
@@ -335,6 +338,16 @@ public class JIoEndpoint extends Abstrac
                     if (launch) {
                         try {
                             getExecutor().execute(new SocketProcessor(socket, SocketStatus.OPEN));
+                        } catch (RejectedExecutionException x) {
+                            log.warn("Socket reprocessing request was rejected for:"+socket,x);
+                            try {
+                                //unable to handle connection at this time
+                                handler.process(socket, SocketStatus.DISCONNECT);
+                            } finally {
+                                countDownConnection();
+                            }
+
+
                         } catch (NullPointerException npe) {
                             if (running) {
                                 log.error(sm.getString("endpoint.launch.fail"),
@@ -560,6 +573,7 @@ public class JIoEndpoint extends Abstrac
                             return false;
                         }
                         getExecutor().execute(proc);
+                        //TODO gotta catch RejectedExecutionException and properly handle it
                     } finally {
                         if (Constants.IS_SECURITY_ENABLED) {
                             PrivilegedAction<Void> pa = new PrivilegedSetTccl(loader);

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1333114&r1=1333113&r2=1333114&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Wed May  2 17:12:48 2012
@@ -787,6 +787,8 @@ public class NioEndpoint extends Abstrac
                         // socket
                         socket = serverSock.accept();
                     } catch (IOException ioe) {
+                        //we didn't get a socket
+                        countDownConnection();
                         // Introduce delay if necessary
                         errorDelay = handleExceptionWithDelay(errorDelay);
                         // re-throw
@@ -799,9 +801,11 @@ public class NioEndpoint extends Abstrac
                     // if successful
                     if (running && !paused) {
                         if (!setSocketOptions(socket)) {
+                            countDownConnection();
                             closeSocket(socket);
                         }
                     } else {
+                        countDownConnection();
                         closeSocket(socket);
                     }
                 } catch (SocketTimeoutException sx) {

Modified: tomcat/trunk/java/org/apache/tomcat/util/threads/LimitLatch.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/threads/LimitLatch.java?rev=1333114&r1=1333113&r2=1333114&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/threads/LimitLatch.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/threads/LimitLatch.java Wed May  2 17:12:48 2012
@@ -20,6 +20,9 @@ import java.util.Collection;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.locks.AbstractQueuedSynchronizer;
 
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
 /**
  * Shared latch that allows the latch to be acquired a limited number of times
  * after which all subsequent requests to acquire the latch will be placed in a
@@ -27,6 +30,8 @@ import java.util.concurrent.locks.Abstra
  */
 public class LimitLatch {
 
+    private static final Log log = LogFactory.getLog(LimitLatch.class);
+
     private class Sync extends AbstractQueuedSynchronizer {
         private static final long serialVersionUID = 1L;
 
@@ -68,6 +73,14 @@ public class LimitLatch {
     }
 
     /**
+     * Returns the current count for the latch
+     * @return the current count for latch
+     */
+    public long getCount() {
+        return count.get();
+    }
+
+    /**
      * Obtain the current limit.
      */
     public long getLimit() {
@@ -96,6 +109,9 @@ public class LimitLatch {
      * latch is current available.
      */
     public void countUpOrAwait() throws InterruptedException {
+        if (log.isDebugEnabled()) {
+            log.debug("Counting up["+Thread.currentThread().getName()+"] latch="+getCount());
+        }
         sync.acquireSharedInterruptibly(1);
     }
 
@@ -105,7 +121,11 @@ public class LimitLatch {
      */
     public long countDown() {
         sync.releaseShared(0);
-        return count.get();
+        long result = getCount();
+        if (log.isDebugEnabled()) {
+            log.debug("Counting down["+Thread.currentThread().getName()+"] latch="+result);
+    }
+        return result;
     }
 
     /**

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1333114&r1=1333113&r2=1333114&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed May  2 17:12:48 2012
@@ -82,6 +82,16 @@
       </scode>
     </changelog>
   </subsection>
+  <subsection name="jdbc-pool">
+    <changelog>
+      <fix><bug>51237</bug><rev>1302902</rev> Slow Query Report should log using WARN level when queries are slow and within the threshold of caching it</fix>
+      <fix><bug>52002</bug><rev>1302948</rev> Add in configuration option to disallow connection reuse</fix>
+      <fix><bug>52493</bug><rev>1302969</rev> Java 7 DataSource method addition</fix>
+      <fix><bug>51893</bug><rev>1302990</rev> Throw an error and notification when pool is exhausted</fix>
+      <fix><bug>50860</bug><rev>1303031</rev> Add in option to configure logging for validation errors</fix>
+    </changelog>
+  </subsection>
+
   <subsection name="Other">
     <changelog>
       <scode>

Modified: tomcat/trunk/webapps/docs/config/ajp.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/ajp.xml?rev=1333114&r1=1333113&r2=1333114&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/ajp.xml (original)
+++ tomcat/trunk/webapps/docs/config/ajp.xml Wed May  2 17:12:48 2012
@@ -349,7 +349,9 @@
       For APR/native, the default is <code>8192</code>.</p>
       <p>Note that for APR/native on Windows, the configured value will be
       reduced to the highest multiple of 1024 that is less than or equal to
-      maxConnections. This is done for performance reasons.</p>
+      maxConnections. This is done for performance reasons.<br/>
+      If set to a value of -1, the maxConnections feature is disabled 
+      and connections are not counted.</p>
     </attribute>
 
     <attribute name="maxThreads" required="false">

Modified: tomcat/trunk/webapps/docs/config/http.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/http.xml?rev=1333114&r1=1333113&r2=1333114&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/http.xml (original)
+++ tomcat/trunk/webapps/docs/config/http.xml Wed May  2 17:12:48 2012
@@ -384,7 +384,9 @@
       For APR/native, the default is <code>8192</code>.</p>
       <p>Note that for APR/native on Windows, the configured value will be
       reduced to the highest multiple of 1024 that is less than or equal to
-      maxConnections. This is done for performance reasons.</p>
+      maxConnections. This is done for performance reasons.<br/>
+      If set to a value of -1, the maxConnections feature is disabled 
+      and connections are not counted.</p>
     </attribute>
 
     <attribute name="maxHttpHeaderSize" required="false">



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