Ensure APR socket is not added to multiple pollers.
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 28 Jul 2011 18:16:39 +0000 (18:16 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 28 Jul 2011 18:16:39 +0000 (18:16 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1151953 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/coyote/AbstractProtocol.java
java/org/apache/coyote/http11/Http11AprProcessor.java
java/org/apache/tomcat/util/net/AbstractEndpoint.java
webapps/docs/changelog.xml

index 63142cf..a573e88 100644 (file)
@@ -525,10 +525,15 @@ public abstract class AbstractProtocol implements ProtocolHandler,
                     // socket associated with the processor. Exact requirements
                     // depend on type of long poll
                     longPoll(socket, processor);
-                } else if (state == SocketState.OPEN){
+                } else if (state == SocketState.OPEN) {
                     // In keep-alive but between requests. OK to recycle
                     // processor. Continue to poll for the next request.
                     release(socket, processor, false, true);
+                } else if (state == SocketState.SENDFILE) {
+                    // Sendfile in progress. If it fails, the socket will be
+                    // closed. If it works, the socket will be re-added to the
+                    // poller
+                    release(socket, processor, false, false);
                 } else {
                     // Connection closed. OK to recycle the processor.
                     release(socket, processor, true, false);
index 3b7e2e2..f92bee1 100644 (file)
@@ -185,6 +185,7 @@ public class Http11AprProcessor extends AbstractHttp11Processor<Long> {
         
         boolean keptAlive = false;
         boolean openSocket = false;
+        boolean sendfileInProgress = false;
 
         while (!error && keepAlive && !comet && !isAsync() && !endpoint.isPaused()) {
 
@@ -305,17 +306,19 @@ public class Http11AprProcessor extends AbstractHttp11Processor<Long> {
                 sendfileData.socket = socketRef;
                 sendfileData.keepAlive = keepAlive;
                 if (!((AprEndpoint)endpoint).getSendfile().add(sendfileData)) {
+                    // Didn't send all of the data to sendfile.
                     if (sendfileData.socket == 0) {
-                        // Didn't send all the data but the socket is no longer
-                        // set. Something went wrong. Close the connection.
-                        // Too late to set status code.
+                        // The socket is no longer set. Something went wrong.
+                        // Close the connection. Too late to set status code.
                         if (log.isDebugEnabled()) {
                             log.debug(sm.getString(
                                     "http11processor.sendfile.error"));
                         }
                         error = true;
                     } else {
-                        openSocket = true;
+                        // The sendfile Poller will add the socket to the main
+                        // Poller once sendfile processing is complete
+                        sendfileInProgress = true;
                     }
                     break;
                 }
@@ -332,7 +335,11 @@ public class Http11AprProcessor extends AbstractHttp11Processor<Long> {
         } else if (comet  || isAsync()) {
             return SocketState.LONG;
         } else {
-            return (openSocket) ? SocketState.OPEN : SocketState.CLOSED;
+            if (sendfileInProgress) {
+                return SocketState.SENDFILE;
+            } else {
+                return (openSocket) ? SocketState.OPEN : SocketState.CLOSED;
+            }
         }
         
     }
index 1b45069..f606817 100644 (file)
@@ -54,7 +54,7 @@ public abstract class AbstractEndpoint {
         public enum SocketState {
             // TODO Add a new state to the AsyncStateMachine and remove
             //      ASYNC_END (if possible)
-            OPEN, CLOSED, LONG, ASYNC_END
+            OPEN, CLOSED, LONG, ASYNC_END, SENDFILE
         }
         
 
index 2a36164..071b9a2 100644 (file)
         Improve error handling for HTTP APR if an error occurs while using
         sendfile. (markt) 
       </add>
+      <fix>
+        Ensure that when using sendfile, HTTP APR sockets are not added to
+        multiple pollers. This may cause errors during shutdown. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">