Author: markt
Date: Sat Feb 14 16:40:20 2015
New Revision: 1659806

URL: http://svn.apache.org/r1659806
Log:
Fix a concurrency issue in the APR Poller that meant it was possible under low 
load for a socket queued to be added to the Poller not to be added for 10 
seconds.

Modified:
    tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java

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=1659806&r1=1659805&r2=1659806&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Sat Feb 14 
16:40:20 2015
@@ -1636,7 +1636,15 @@ public class AprEndpoint extends Abstrac
                             maintain();
                         }
                         synchronized (this) {
-                            this.wait(10000);
+                            // Make sure that no sockets have been placed in 
the
+                            // addList or closeList since the check above.
+                            // Without this check there could be a 10s pause
+                            // with no processing since the notify() call in
+                            // add()/close() would have no effect since it
+                            // happened before this sync block was entered
+                            if (addList.size() < 1 && closeList.size() < 1) {
+                                this.wait(10000);
+                            }
                         }
                     } catch (InterruptedException e) {
                         // Ignore
@@ -1654,25 +1662,25 @@ public class AprEndpoint extends Abstrac
                 try {
                     // Duplicate the add and remove lists so that the syncs are
                     // minimised
-                    if (closeList.size() > 0) {
-                        synchronized (this) {
+                    synchronized (this) {
+                        if (closeList.size() > 0) {
                             // Duplicate to another list, so that the syncing 
is
                             // minimal
                             closeList.duplicate(localCloseList);
                             closeList.clear();
+                        } else {
+                            localCloseList.clear();
                         }
-                    } else {
-                        localCloseList.clear();
                     }
-                    if (addList.size() > 0) {
-                        synchronized (this) {
+                    synchronized (this) {
+                        if (addList.size() > 0) {
                             // Duplicate to another list, so that the syncing 
is
                             // minimal
                             addList.duplicate(localAddList);
                             addList.clear();
+                        } else {
+                            localAddList.clear();
                         }
-                    } else {
-                        localAddList.clear();
                     }
 
                     // Remove sockets



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

Reply via email to