You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by vi...@apache.org on 2016/12/10 17:30:35 UTC

svn commit: r1773527 - in /tomcat/tc8.0.x/trunk: java/org/apache/coyote/http11/Http11AprProcessor.java java/org/apache/tomcat/util/net/AprEndpoint.java test/org/apache/catalina/connector/TestSendFile.java webapps/docs/changelog.xml

Author: violetagg
Date: Sat Dec 10 17:30:35 2016
New Revision: 1773527

URL: http://svn.apache.org/viewvc?rev=1773527&view=rev
Log:
Prevent read time out when the file is deleted while serving the response.
The issue was observed only with APR Connector and sendfile enabled.

Modified:
    tomcat/tc8.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
    tomcat/tc8.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
    tomcat/tc8.0.x/trunk/test/org/apache/catalina/connector/TestSendFile.java
    tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml

Modified: tomcat/tc8.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java?rev=1773527&r1=1773526&r2=1773527&view=diff
==============================================================================
--- tomcat/tc8.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java (original)
+++ tomcat/tc8.0.x/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java Sat Dec 10 17:30:35 2016
@@ -199,21 +199,22 @@ public class Http11AprProcessor extends
         if (sendfileData != null && !getErrorState().isError()) {
             sendfileData.socket = socketWrapper.getSocket().longValue();
             sendfileData.keepAlive = keepAlive;
-            if (!((AprEndpoint)endpoint).getSendfile().add(sendfileData)) {
-                // Didn't send all of the data to sendfile.
-                if (sendfileData.socket == 0) {
-                    // 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"));
-                    }
-                    setErrorState(ErrorState.CLOSE_NOW, null);
-                } else {
-                    // The sendfile Poller will add the socket to the main
-                    // Poller once sendfile processing is complete
-                    sendfileInProgress = true;
+            switch (((AprEndpoint)endpoint).getSendfile().add(sendfileData)) {
+            case DONE:
+                return false;
+            case PENDING:
+                // The sendfile Poller will add the socket to the main
+                // Poller once sendfile processing is complete
+                sendfileInProgress = true;
+                return true;
+            case ERROR:
+                // Something went wrong.
+                // Close the connection. Too late to set status code.
+                if (log.isDebugEnabled()) {
+                    log.debug(sm.getString(
+                            "http11processor.sendfile.error"));
                 }
+                setErrorState(ErrorState.CLOSE_NOW, null);
                 return true;
             }
         }

Modified: tomcat/tc8.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1773527&r1=1773526&r2=1773527&view=diff
==============================================================================
--- tomcat/tc8.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/tc8.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Sat Dec 10 17:30:35 2016
@@ -2166,7 +2166,7 @@ public class AprEndpoint extends Abstrac
          * @return true if all the data has been sent right away, and false
          *              otherwise
          */
-        public boolean add(SendfileData data) {
+        public SendfileState add(SendfileData data) {
             // Initialize fd from data given
             try {
                 data.fdpool = Socket.pool(data.socket);
@@ -2184,7 +2184,7 @@ public class AprEndpoint extends Abstrac
                         if (!(-nw == Status.EAGAIN)) {
                             Pool.destroy(data.fdpool);
                             data.socket = 0;
-                            return false;
+                            return SendfileState.ERROR;
                         } else {
                             // Break the loop and add the socket to poller.
                             break;
@@ -2197,13 +2197,13 @@ public class AprEndpoint extends Abstrac
                             // Set back socket to blocking mode
                             Socket.timeoutSet(
                                     data.socket, getSoTimeout() * 1000);
-                            return true;
+                            return SendfileState.DONE;
                         }
                     }
                 }
             } catch (Exception e) {
                 log.warn(sm.getString("endpoint.sendfile.error"), e);
-                return false;
+                return SendfileState.ERROR;
             }
             // Add socket to the list. Newly added sockets will wait
             // at most for pollTime before being polled
@@ -2211,7 +2211,7 @@ public class AprEndpoint extends Abstrac
                 addS.add(data);
                 this.notify();
             }
-            return false;
+            return SendfileState.PENDING;
         }
 
         /**

Modified: tomcat/tc8.0.x/trunk/test/org/apache/catalina/connector/TestSendFile.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/test/org/apache/catalina/connector/TestSendFile.java?rev=1773527&r1=1773526&r2=1773527&view=diff
==============================================================================
--- tomcat/tc8.0.x/trunk/test/org/apache/catalina/connector/TestSendFile.java (original)
+++ tomcat/tc8.0.x/trunk/test/org/apache/catalina/connector/TestSendFile.java Sat Dec 10 17:30:35 2016
@@ -39,7 +39,6 @@ import javax.servlet.http.HttpServletRes
 import static org.junit.Assert.assertEquals;
 
 import org.junit.Assert;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import org.apache.catalina.Context;
@@ -154,7 +153,6 @@ public class TestSendFile extends Tomcat
     }
 
 
-    @Ignore
     @Test
     public void testBug60409() throws Exception {
         Tomcat tomcat = getTomcatInstance();

Modified: tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml?rev=1773527&r1=1773526&r2=1773527&view=diff
==============================================================================
--- tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml Sat Dec 10 17:30:35 2016
@@ -113,6 +113,11 @@
         of a specific type such as <code>0.0.0.0</code> or <code>::</code>.
         (markt)
       </fix>
+      <fix>
+        Prevent read time out when the file is deleted while serving the
+        response. The issue was observed only with APR Connector and
+        sendfile enabled. (violetagg)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">



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