Author: markt Date: Fri Mar 21 23:04:07 2014 New Revision: 1580080 URL: http://svn.apache.org/r1580080 Log: Rework the fix for 56190 as the previous fix did not recycle the request in all cases leading to mis-routing of requests.
Modified: tomcat/trunk/java/org/apache/catalina/core/AsyncContextImpl.java tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties tomcat/trunk/java/org/apache/coyote/AsyncContextCallback.java tomcat/trunk/java/org/apache/coyote/AsyncStateMachine.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/catalina/core/AsyncContextImpl.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/AsyncContextImpl.java?rev=1580080&r1=1580079&r2=1580080&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/AsyncContextImpl.java (original) +++ tomcat/trunk/java/org/apache/catalina/core/AsyncContextImpl.java Fri Mar 21 23:04:07 2014 @@ -88,9 +88,7 @@ public class AsyncContextImpl implements } @Override - public void fireOnComplete() throws IOException { - // Before firing the event, close the response - request.getResponse().finishResponse(); + public void fireOnComplete() { List<AsyncListenerWrapper> listenersCopy = new ArrayList<>(); listenersCopy.addAll(listeners); @@ -108,6 +106,18 @@ public class AsyncContextImpl implements } finally { context.unbind(Globals.IS_SECURITY_ENABLED, oldCL); } + + // The application doesn't know it has to stop writing until it receives + // the complete event so the response has to be closed after firing the + // event. + try { + request.getResponse().finishResponse(); + } catch (IOException ioe) { + // Catch this here and allow async context complete to continue + // normally so a dispatch takes place which ensures that the + // request and response objects are correctly recycled. + log.debug(sm.getString("asyncContextImpl.finishResponseError"), ioe); + } } public boolean timeout() { Modified: tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=1580080&r1=1580079&r2=1580080&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties (original) +++ tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties Fri Mar 21 23:04:07 2014 @@ -65,6 +65,7 @@ aprListener.tooLateForSSLRandomSeed=Cann aprListener.tooLateForFIPSMode=Cannot setFIPSMode: SSL has already been initialized aprListener.initializedOpenSSL=OpenSSL successfully initialized ({0}) +asyncContextImpl.finishResponseError=Response did not finish cleanly after AsyncContext completed asyncContextImpl.request.ise=It is illegal to call getRequest() after complete() or any of the dispatch() methods has been called asyncContextImpl.requestEnded=The request associated with the AsyncContext has already completed processing. asyncContextImpl.response.ise=It is illegal to call getResponse() after complete() or any of the dispatch() methods has been called Modified: tomcat/trunk/java/org/apache/coyote/AsyncContextCallback.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/AsyncContextCallback.java?rev=1580080&r1=1580079&r2=1580080&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/AsyncContextCallback.java (original) +++ tomcat/trunk/java/org/apache/coyote/AsyncContextCallback.java Fri Mar 21 23:04:07 2014 @@ -16,8 +16,6 @@ */ package org.apache.coyote; -import java.io.IOException; - /** * Provides a mechanism for the Coyote connectors to signal to a * {@link javax.servlet.AsyncContext} implementation that an action, such as @@ -26,5 +24,5 @@ import java.io.IOException; * org.apache.coyote package. */ public interface AsyncContextCallback { - public void fireOnComplete() throws IOException; + public void fireOnComplete(); } Modified: tomcat/trunk/java/org/apache/coyote/AsyncStateMachine.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/AsyncStateMachine.java?rev=1580080&r1=1580079&r2=1580080&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/AsyncStateMachine.java (original) +++ tomcat/trunk/java/org/apache/coyote/AsyncStateMachine.java Fri Mar 21 23:04:07 2014 @@ -16,7 +16,6 @@ */ package org.apache.coyote; -import java.io.IOException; import java.security.AccessController; import java.security.PrivilegedAction; @@ -204,21 +203,11 @@ public class AsyncStateMachine<S> { state = AsyncState.STARTED; return SocketState.LONG; } else if (state == AsyncState.MUST_COMPLETE) { - try { - asyncCtxt.fireOnComplete(); - } catch (IOException e) { - // Socket is in unknown state. Close it. - return SocketState.CLOSED; - } + asyncCtxt.fireOnComplete(); state = AsyncState.DISPATCHED; return SocketState.ASYNC_END; } else if (state == AsyncState.COMPLETING) { - try { - asyncCtxt.fireOnComplete(); - } catch (IOException e) { - // Socket is in unknown state. Close it. - return SocketState.CLOSED; - } + asyncCtxt.fireOnComplete(); state = AsyncState.DISPATCHED; return SocketState.ASYNC_END; } else if (state == AsyncState.MUST_DISPATCH) { Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1580080&r1=1580079&r2=1580080&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Fri Mar 21 23:04:07 2014 @@ -45,6 +45,12 @@ issues to not "pop up" wrt. others). --> <section name="Tomcat 8.0.5 (markt)"> + <subsection name="Catalina"> + <changelog> + Rework the fix for <bug>56190</bug> as the previous fix did not recycle + the request in all cases leading to mis-routing of requests. (markt) + </changelog> + </subsection> <subsection name="Coyote"> <changelog> <fix> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org