Author: remm Date: Tue Jul 8 11:55:24 2014 New Revision: 1608737 URL: http://svn.apache.org/r1608737 Log: Avoid doing anything if the endpoint is not running (avoids possible NPE with the caches (?) ) and create caches first in start (just in case). Note: I still don't see much real benefit in these caches, and their configuration is even more questionable (but it is there and documented).
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java?rev=1608737&r1=1608736&r2=1608737&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Tue Jul 8 11:55:24 2014 @@ -345,11 +345,6 @@ public class Nio2Endpoint extends Abstra running = true; paused = false; - // Create worker collection - if ( getExecutor() == null ) { - createExecutor(); - } - if (useCaches) { processorCache = new SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE, socketProperties.getProcessorCache()); @@ -359,6 +354,11 @@ public class Nio2Endpoint extends Abstra socketProperties.getBufferPool()); } + // Create worker collection + if ( getExecutor() == null ) { + createExecutor(); + } + initializeConnectionLatch(); startAcceptorThreads(); @@ -384,30 +384,30 @@ public class Nio2Endpoint extends Abstra running = false; getAsyncTimeout().stop(); unlockAccept(); - } - // Use the executor to avoid binding the main thread if something bad - // occurs and unbind will also wait for a bit for it to complete - getExecutor().execute(new Runnable() { - @Override - public void run() { - // Timeout any pending async request - for (SocketWrapper<Nio2Channel> socket : waitingRequests) { - processSocket(socket, SocketStatus.TIMEOUT, false); - } - // Then close all active connections if any remains - try { - handler.closeAll(); - } catch (Throwable t) { - ExceptionUtils.handleThrowable(t); - } finally { - allClosed = true; + // Use the executor to avoid binding the main thread if something bad + // occurs and unbind will also wait for a bit for it to complete + getExecutor().execute(new Runnable() { + @Override + public void run() { + // Timeout any pending async request + for (SocketWrapper<Nio2Channel> socket : waitingRequests) { + processSocket(socket, SocketStatus.TIMEOUT, false); + } + // Then close all active connections if any remains + try { + handler.closeAll(); + } catch (Throwable t) { + ExceptionUtils.handleThrowable(t); + } finally { + allClosed = true; + } } + }); + if (useCaches) { + socketWrapperCache.clear(); + nioChannels.clear(); + processorCache.clear(); } - }); - if (useCaches) { - socketWrapperCache.clear(); - nioChannels.clear(); - processorCache.clear(); } } Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1608737&r1=1608736&r2=1608737&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Tue Jul 8 11:55:24 2014 @@ -401,11 +401,6 @@ public class NioEndpoint extends Abstrac running = true; paused = false; - // Create worker collection - if ( getExecutor() == null ) { - createExecutor(); - } - processorCache = new SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE, socketProperties.getProcessorCache()); keyCache = new SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE, @@ -415,6 +410,11 @@ public class NioEndpoint extends Abstrac nioChannels = new SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE, socketProperties.getBufferPool()); + // Create worker collection + if ( getExecutor() == null ) { + createExecutor(); + } + initializeConnectionLatch(); // Start poller threads @@ -453,12 +453,12 @@ public class NioEndpoint extends Abstrac stopLatch.await(selectorTimeout + 100, TimeUnit.MILLISECONDS); } catch (InterruptedException ignore) { } + shutdownExecutor(); + eventCache.clear(); + keyCache.clear(); + nioChannels.clear(); + processorCache.clear(); } - eventCache.clear(); - keyCache.clear(); - nioChannels.clear(); - processorCache.clear(); - shutdownExecutor(); } Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1608737&r1=1608736&r2=1608737&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Tue Jul 8 11:55:24 2014 @@ -131,6 +131,10 @@ to data available, remaining and extra write events, mostly occurring with non blocking Servlet 3.1. (remm) </fix> + <fix> + Avoid possible NPE stopping endpoints that are not started (stop + shouldn't do anything in that case). (remm) + </fix> </changelog> </subsection> <subsection name="Jasper"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org