https://issues.apache.org/bugzilla/show_bug.cgi?id=51794
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 14 Sep 2011 14:39:05 +0000 (14:39 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 14 Sep 2011 14:39:05 +0000 (14:39 +0000)
Fix race condition in selector potentially causing a delay in select operations

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

java/org/apache/tomcat/util/net/NioEndpoint.java

index ca8ba2d..6a2ae91 100644 (file)
@@ -1081,13 +1081,11 @@ public class NioEndpoint extends AbstractEndpoint {
                     }
                     try {
                         if ( !close ) {
-                            if (wakeupCounter.get()>0) {
+                            if (wakeupCounter.getAndSet(-1) > 0) {
                                 //if we are here, means we have other stuff to do
                                 //do a non blocking select
                                 keyCount = selector.selectNow();
-                            }else {
-                                keyCount = selector.keys().size();
-                                wakeupCounter.set(-1);
+                            } else {
                                 keyCount = selector.select(selectorTimeout);
                             }
                             wakeupCounter.set(0);