Don't assume servlet 3+ async when processing long poll connections (it might be...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 26 Jan 2011 16:11:46 +0000 (16:11 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 26 Jan 2011 16:11:46 +0000 (16:11 +0000)
Use socket rather than socket wrapper as key in connection list else comet sockets may be lost

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

java/org/apache/coyote/http11/Http11AprProtocol.java
java/org/apache/tomcat/util/net/AprEndpoint.java
webapps/docs/changelog.xml

index 916520b..a706cac 100644 (file)
@@ -204,8 +204,8 @@ public class Http11AprProtocol extends AbstractHttp11Protocol {
         protected AtomicLong registerCount = new AtomicLong(0);
         protected RequestGroupInfo global = new RequestGroupInfo();
         
-        protected ConcurrentHashMap<SocketWrapper<Long>, Http11AprProcessor> connections =
-            new ConcurrentHashMap<SocketWrapper<Long>, Http11AprProcessor>();
+        protected ConcurrentHashMap<Long, Http11AprProcessor> connections =
+            new ConcurrentHashMap<Long, Http11AprProcessor>();
 
         protected ConcurrentLinkedQueue<Http11AprProcessor> recycledProcessors = 
             new ConcurrentLinkedQueue<Http11AprProcessor>() {
@@ -264,7 +264,7 @@ public class Http11AprProtocol extends AbstractHttp11Protocol {
         
         @Override
         public SocketState event(SocketWrapper<Long> socket, SocketStatus status) {
-            Http11AprProcessor processor = connections.get(socket);
+            Http11AprProcessor processor = connections.get(socket.getSocket());
             
             SocketState state = SocketState.CLOSED; 
             if (processor != null) {
@@ -294,7 +294,7 @@ public class Http11AprProtocol extends AbstractHttp11Protocol {
                                 "http11protocol.proto.error"), e);
                     } finally {
                         if (state != SocketState.LONG) {
-                            connections.remove(socket);
+                            connections.remove(socket.getSocket());
                             socket.setAsync(false);
                             recycledProcessors.offer(processor);
                             if (state == SocketState.OPEN) {
@@ -329,8 +329,13 @@ public class Http11AprProtocol extends AbstractHttp11Protocol {
                 if (state == SocketState.LONG || state == SocketState.ASYNC_END) {
                     // Need to make socket available for next processing cycle
                     // but no need for the poller
-                    connections.put(socket, processor);
-                    socket.setAsync(true);
+                    connections.put(socket.getSocket(), processor);
+                    if (processor.isAsync()) {
+                        socket.setAsync(true);
+                    } else if (processor.comet) {
+                        ((AprEndpoint) proto.endpoint).getCometPoller().add(
+                                socket.getSocket().longValue());
+                    }
                 } else {
                     recycledProcessors.offer(processor);
                 }
@@ -362,7 +367,7 @@ public class Http11AprProtocol extends AbstractHttp11Protocol {
 
         @Override
         public SocketState asyncDispatch(SocketWrapper<Long> socket, SocketStatus status) {
-            Http11AprProcessor result = connections.get(socket);
+            Http11AprProcessor result = connections.get(socket.getSocket());
             
             SocketState state = SocketState.CLOSED; 
             if (result != null) {
index dcb912e..1d0ef85 100644 (file)
@@ -1688,7 +1688,9 @@ public class AprEndpoint extends AbstractEndpoint {
                     socket = null;
                 } else if (state == Handler.SocketState.LONG) {
                     socket.access();
-                    waitingRequests.add(socket);
+                    if (socket.async) {
+                        waitingRequests.add(socket);
+                    }
                 } else if (state == Handler.SocketState.ASYNC_END) {
                     socket.access();
                     SocketProcessor proc = new SocketProcessor(socket, SocketStatus.OPEN);
index 1d16455..2f67901 100644 (file)
         <bug>50627</bug>: Correct interaction of NIO socket and Poller when
         processing Comet events. (markt)
       </fix>
+      <fix>
+        Correct interaction of APR socket and Poller when processing Comet
+        events. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">