You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2015/07/02 22:29:35 UTC
svn commit: r1688901 -
/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
Author: markt
Date: Thu Jul 2 20:29:35 2015
New Revision: 1688901
URL: http://svn.apache.org/r1688901
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=57943
Prevent the same socket being added to the cache twice.
Patch based on analysis by Ian Luo / Sun Qi
Modified:
tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
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=1688901&r1=1688900&r2=1688901&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Thu Jul 2 20:29:35 2015
@@ -1521,36 +1521,12 @@ public class NioEndpoint extends Abstrac
state = handler.process(ka, status);
}
if (state == SocketState.CLOSED) {
- // Close socket and pool
- try {
- if (socket.getPoller().cancelledKey(key) != null) {
- // SocketWrapper (attachment) was removed from the
- // key - recycle the key. This can only happen once
- // per attempted closure so it is used to determine
- // whether or not to return the key to the cache.
- // We do NOT want to do this more than once - see BZ
- // 57340.
- if (running && !paused) {
- if (!nioChannels.push(socket)) {
- socket.free();
- }
- }
- socket = null;
- }
- ka = null;
- } catch (Exception x) {
- log.error("",x);
- }
+ close(socket, key);
+ socket = null;
+ ka = null;
}
} else if (handshake == -1 ) {
- if (key != null) {
- socket.getPoller().cancelledKey(key);
- }
- if (running && !paused) {
- if (!nioChannels.push(socket)) {
- socket.free();
- }
- }
+ close(socket, key);
socket = null;
ka = null;
} else {
@@ -1577,6 +1553,26 @@ public class NioEndpoint extends Abstrac
}
}
}
+
+ private void close(NioChannel socket, SelectionKey key) {
+ try {
+ if (socket.getPoller().cancelledKey(key) != null) {
+ // SocketWrapper (attachment) was removed from the
+ // key - recycle the key. This can only happen once
+ // per attempted closure so it is used to determine
+ // whether or not to return the key to the cache.
+ // We do NOT want to do this more than once - see BZ
+ // 57340 / 57943.
+ if (running && !paused) {
+ if (!nioChannels.push(socket)) {
+ socket.free();
+ }
+ }
+ }
+ } catch (Exception x) {
+ log.error("",x);
+ }
+ }
}
// ----------------------------------------------- SendfileData Inner Class
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org