Author: markt
Date: Wed Aug 9 11:43:17 2017
New Revision: 1804506
URL: http://svn.apache.org/viewvc?rev=1804506&view=rev
Log:
Prevent exceptions being thrown during normal shutdown of NIO connections. This
enables TLS connections to close cleanly.
Modified:
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/NioEndpoint.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1804506&r1=1804505&r2=1804506&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Wed Aug 9
11:43:17 2017
@@ -643,6 +643,22 @@ public class NioEndpoint extends Abstrac
getHandler().release(ka);
}
if (key.isValid()) key.cancel();
+ // If it is available, close the NioChannel first which should
+ // in turn close the underlying SocketChannel. The NioChannel
+ // needs to be closed first, if available, to ensure that TLS
+ // connections are shut down cleanly.
+ if (ka != null) {
+ try {
+ ka.getSocket().close(true);
+ } catch (Exception e){
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString(
+ "endpoint.debug.socketCloseFail"), e);
+ }
+ }
+ }
+ // The SocketChannel is also available via the SelectionKey. If
+ // it hasn't been closed in the block above, close it now.
if (key.channel().isOpen()) {
try {
key.channel().close();
@@ -654,16 +670,6 @@ public class NioEndpoint extends Abstrac
}
}
try {
- if (ka!=null) {
- ka.getSocket().close(true);
- }
- } catch (Exception e){
- if (log.isDebugEnabled()) {
- log.debug(sm.getString(
- "endpoint.debug.socketCloseFail"), e);
- }
- }
- try {
if (ka != null && ka.getSendfileData() != null
&& ka.getSendfileData().fchannel != null
&& ka.getSendfileData().fchannel.isOpen()) {
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1804506&r1=1804505&r2=1804506&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed Aug 9 11:43:17 2017
@@ -68,6 +68,10 @@
Improve the handling of client disconnections during the TLS
renegotiation handshake. (markt)
</fix>
+ <fix>
+ Prevent exceptions being thrown during normal shutdown of NIO
+ connections. This enables TLS connections to close cleanly. (markt)
+ </fix>
</changelog>
</subsection>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]