Prevent exceptions being thrown during normal shutdown of NIO connections. This enables TLS connections to close cleanly.
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc8.0.x/trunk@1804562 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/java/org/apache/tomcat/util/net/NioBlockingSelector.java b/java/org/apache/tomcat/util/net/NioBlockingSelector.java
index 2f87e4c..ee0d425 100644
--- a/java/org/apache/tomcat/util/net/NioBlockingSelector.java
+++ b/java/org/apache/tomcat/util/net/NioBlockingSelector.java
@@ -386,13 +386,20 @@
}
}
events.clear();
- try {
- selector.selectNow();//cancel all remaining keys
- }catch( Exception ignore ) {
- if (log.isDebugEnabled())log.debug("",ignore);
+ // If using a shared selector, the NioSelectorPool will also try and
+ // close the selector. Try and avoid the ClosedSelectorException
+ // although because multiple threads are involved there is always
+ // the possibility of an Exception here.
+ if (selector.isOpen()) {
+ try {
+ // Cancels all remaining keys
+ selector.selectNow();
+ }catch( Exception ignore ) {
+ if (log.isDebugEnabled())log.debug("",ignore);
+ }
}
try {
- selector.close();//Close the connector
+ selector.close();
}catch( Exception ignore ) {
if (log.isDebugEnabled())log.debug("",ignore);
}