Author: markt Date: Tue Oct 8 07:55:22 2013 New Revision: 1530177 URL: http://svn.apache.org/r1530177 Log: Revert r1529130 and add a comment that explains why the sync is necessary.
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1530177&r1=1530176&r2=1530177&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Tue Oct 8 07:55:22 2013 @@ -855,32 +855,37 @@ public class AprEndpoint extends Abstrac public void processSocket(SocketWrapper<Long> socket, SocketStatus status, boolean dispatch) { try { - if (waitingRequests.remove(socket)) { - SocketProcessor proc = new SocketProcessor(socket, status); - Executor executor = getExecutor(); - if (dispatch && executor != null) { - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - try { - //threads should not be created by the webapp classloader - if (Constants.IS_SECURITY_ENABLED) { - PrivilegedAction<Void> pa = new PrivilegedSetTccl( - getClass().getClassLoader()); - AccessController.doPrivileged(pa); - } else { - Thread.currentThread().setContextClassLoader( - getClass().getClassLoader()); - } - executor.execute(proc); - } finally { - if (Constants.IS_SECURITY_ENABLED) { - PrivilegedAction<Void> pa = new PrivilegedSetTccl(loader); - AccessController.doPrivileged(pa); - } else { - Thread.currentThread().setContextClassLoader(loader); + // Synchronisation is required here as this code may be called as a + // result of calling AsyncContext.dispatch() from a non-container + // thread + synchronized (socket) { + if (waitingRequests.remove(socket)) { + SocketProcessor proc = new SocketProcessor(socket, status); + Executor executor = getExecutor(); + if (dispatch && executor != null) { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + try { + //threads should not be created by the webapp classloader + if (Constants.IS_SECURITY_ENABLED) { + PrivilegedAction<Void> pa = new PrivilegedSetTccl( + getClass().getClassLoader()); + AccessController.doPrivileged(pa); + } else { + Thread.currentThread().setContextClassLoader( + getClass().getClassLoader()); + } + executor.execute(proc); + } finally { + if (Constants.IS_SECURITY_ENABLED) { + PrivilegedAction<Void> pa = new PrivilegedSetTccl(loader); + AccessController.doPrivileged(pa); + } else { + Thread.currentThread().setContextClassLoader(loader); + } } + } else { + proc.run(); } - } else { - proc.run(); } } } catch (RejectedExecutionException ree) { Modified: tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java?rev=1530177&r1=1530176&r2=1530177&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java Tue Oct 8 07:55:22 2013 @@ -554,37 +554,42 @@ public class JIoEndpoint extends Abstrac public void processSocket(SocketWrapper<Socket> socket, SocketStatus status, boolean dispatch) { try { - if (waitingRequests.remove(socket)) { - SocketProcessor proc = new SocketProcessor(socket,status); - Executor executor = getExecutor(); - if (dispatch && executor != null) { - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - try { - //threads should not be created by the webapp classloader - if (Constants.IS_SECURITY_ENABLED) { - PrivilegedAction<Void> pa = - new PrivilegedSetTccl( - getClass().getClassLoader()); - AccessController.doPrivileged(pa); - } else { - Thread.currentThread().setContextClassLoader( - getClass().getClassLoader()); - } - // During shutdown, executor may be null - avoid NPE - if (!running) { - return; - } - getExecutor().execute(proc); - } finally { - if (Constants.IS_SECURITY_ENABLED) { - PrivilegedAction<Void> pa = new PrivilegedSetTccl(loader); - AccessController.doPrivileged(pa); - } else { - Thread.currentThread().setContextClassLoader(loader); + // Synchronisation is required here as this code may be called as a + // result of calling AsyncContext.dispatch() from a non-container + // thread + synchronized (socket) { + if (waitingRequests.remove(socket)) { + SocketProcessor proc = new SocketProcessor(socket,status); + Executor executor = getExecutor(); + if (dispatch && executor != null) { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + try { + //threads should not be created by the webapp classloader + if (Constants.IS_SECURITY_ENABLED) { + PrivilegedAction<Void> pa = + new PrivilegedSetTccl( + getClass().getClassLoader()); + AccessController.doPrivileged(pa); + } else { + Thread.currentThread().setContextClassLoader( + getClass().getClassLoader()); + } + // During shutdown, executor may be null - avoid NPE + if (!running) { + return; + } + getExecutor().execute(proc); + } finally { + if (Constants.IS_SECURITY_ENABLED) { + PrivilegedAction<Void> pa = new PrivilegedSetTccl(loader); + AccessController.doPrivileged(pa); + } else { + Thread.currentThread().setContextClassLoader(loader); + } } + } else { + proc.run(); } - } else { - proc.run(); } } } catch (RejectedExecutionException ree) { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org