Author: markt Date: Tue Oct 30 09:53:53 2018 New Revision: 1845209 URL: http://svn.apache.org/viewvc?rev=1845209&view=rev Log: Ensure open sockets etc. are cleaned up if the socket binding process fails.
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java?rev=1845209&r1=1845208&r2=1845209&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java Tue Oct 30 09:53:53 2018 @@ -1039,9 +1039,23 @@ public abstract class AbstractEndpoint<S public abstract void startInternal() throws Exception; public abstract void stopInternal() throws Exception; + + private void bindWithCleanup() throws Exception { + try { + bind(); + } catch (Throwable t) { + // Ensure open sockets etc. are cleaned up if something goes + // wrong during bind + ExceptionUtils.handleThrowable(t); + unbind(); + throw t; + } + } + + public final void init() throws Exception { if (bindOnInit) { - bind(); + bindWithCleanup(); bindState = BindState.BOUND_ON_INIT; } if (this.domain != null) { @@ -1105,7 +1119,7 @@ public abstract class AbstractEndpoint<S public final void start() throws Exception { if (bindState == BindState.UNBOUND) { - bind(); + bindWithCleanup(); bindState = BindState.BOUND_ON_START; } startInternal(); Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1845209&r1=1845208&r2=1845209&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Tue Oct 30 09:53:53 2018 @@ -174,6 +174,10 @@ when using NIO/NIO2 and the OpenSSL backed JSSE TLS implementation. (markt) </fix> + <fix> + Ensure open sockets etc. are cleaned up if the socket binding process + fails. (markt) + </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