Author: violetagg Date: Thu Aug 18 13:19:30 2016 New Revision: 1756778 URL: http://svn.apache.org/viewvc?rev=1756778&view=rev Log: Ensure that Semaphore.release is called in all cases. Even when there is an exception.
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.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=1756778&r1=1756777&r2=1756778&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Thu Aug 18 13:19:30 2016 @@ -819,6 +819,10 @@ public class Nio2Endpoint extends Abstra log.debug("Socket: [" + this + "], block: [" + block + "], length: [" + len + "]"); } + if (socketBufferHandler == null) { + throw new IOException(sm.getString("socket.closed")); + } + if (block) { try { readPending.acquire(); @@ -834,9 +838,6 @@ public class Nio2Endpoint extends Abstra } } - if (socketBufferHandler == null) { - throw new IOException(sm.getString("socket.closed")); - } socketBufferHandler.configureReadBufferForRead(); ByteBuffer readBuffer = socketBufferHandler.getReadBuffer(); int remaining = readBuffer.remaining(); @@ -1096,9 +1097,6 @@ public class Nio2Endpoint extends Abstra try { integer = getSocket().read(socketBufferHandler.getReadBuffer()); nRead = integer.get(getNio2ReadTimeout(), TimeUnit.MILLISECONDS).intValue(); - // Blocking read so need to release here since there will - // not be a callback to a completion handler. - readPending.release(); } catch (ExecutionException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); @@ -1110,6 +1108,10 @@ public class Nio2Endpoint extends Abstra } catch (TimeoutException e) { integer.cancel(true); throw new SocketTimeoutException(); + } finally { + // Blocking read so need to release here since there will + // not be a callback to a completion handler. + readPending.release(); } } else { Nio2Endpoint.startInline(); Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1756778&r1=1756777&r2=1756778&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Thu Aug 18 13:19:30 2016 @@ -166,6 +166,10 @@ number of HTTP/2 streams for a connection could not be pruned to below the limit. (markt) </fix> + <fix> + Ensure that <code>Semaphore.release</code> is called in all cases. Even + when there is an exception. (violetagg) + </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