From: markt Date: Thu, 28 Jul 2011 18:16:39 +0000 (+0000) Subject: Ensure APR socket is not added to multiple pollers. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f634a551e03053d3417d03d3e90910648329b8c7;p=tomcat7.0 Ensure APR socket is not added to multiple pollers. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1151953 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/coyote/AbstractProtocol.java b/java/org/apache/coyote/AbstractProtocol.java index 63142cf13..a573e8832 100644 --- a/java/org/apache/coyote/AbstractProtocol.java +++ b/java/org/apache/coyote/AbstractProtocol.java @@ -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); diff --git a/java/org/apache/coyote/http11/Http11AprProcessor.java b/java/org/apache/coyote/http11/Http11AprProcessor.java index 3b7e2e206..f92bee138 100644 --- a/java/org/apache/coyote/http11/Http11AprProcessor.java +++ b/java/org/apache/coyote/http11/Http11AprProcessor.java @@ -185,6 +185,7 @@ public class Http11AprProcessor extends AbstractHttp11Processor { 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 { 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 { } 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; + } } } diff --git a/java/org/apache/tomcat/util/net/AbstractEndpoint.java b/java/org/apache/tomcat/util/net/AbstractEndpoint.java index 1b45069be..f60681768 100644 --- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java +++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java @@ -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 } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 2a36164b5..071b9a20f 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -124,6 +124,10 @@ Improve error handling for HTTP APR if an error occurs while using sendfile. (markt) + + Ensure that when using sendfile, HTTP APR sockets are not added to + multiple pollers. This may cause errors during shutdown. (markt) +