This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push: new 0738909 Make sure the socket is always cleaned up 0738909 is described below commit 073890985b685419fdbf1dde39ddf009268134b8 Author: remm <r...@apache.org> AuthorDate: Fri Jan 8 16:51:17 2021 +0100 Make sure the socket is always cleaned up Cleanup according to the style used for BindState. --- .../apache/tomcat/util/net/AbstractEndpoint.java | 21 +++++++++++++++------ java/org/apache/tomcat/util/net/NioEndpoint.java | 17 ++++++++++------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/java/org/apache/tomcat/util/net/AbstractEndpoint.java b/java/org/apache/tomcat/util/net/AbstractEndpoint.java index 3cc0a64..2c455c3 100644 --- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java +++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java @@ -135,20 +135,26 @@ public abstract class AbstractEndpoint<S,U> { } protected enum BindState { - UNBOUND(false), - BOUND_ON_INIT(true), - BOUND_ON_START(true), - SOCKET_CLOSED_ON_STOP(false); + UNBOUND(false, false), + BOUND_ON_INIT(true, true), + BOUND_ON_START(true, true), + SOCKET_CLOSED_ON_STOP(false, true); private final boolean bound; + private final boolean wasBound; - private BindState(boolean bound) { + private BindState(boolean bound, boolean wasBound) { this.bound = bound; + this.wasBound = wasBound; } public boolean isBound() { return bound; } + + public boolean wasBound() { + return wasBound; + } } @@ -617,7 +623,10 @@ public abstract class AbstractEndpoint<S,U> { private boolean bindOnInit = true; public boolean getBindOnInit() { return bindOnInit; } public void setBindOnInit(boolean b) { this.bindOnInit = b; } - protected volatile BindState bindState = BindState.UNBOUND; + private volatile BindState bindState = BindState.UNBOUND; + protected BindState getBindState() { + return bindState; + } /** * Keepalive timeout, if not set the soTimeout is used. diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index 21f5507..4ccfd4f 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -400,13 +400,16 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel> @Override protected void doCloseServerSocket() throws IOException { - if (!getUseInheritedChannel() && serverSock != null) { - // Close server socket - serverSock.close(); - } - serverSock = null; - if (getUnixDomainSocketPath() != null && bindState != BindState.UNBOUND) { - Files.delete(Paths.get(getUnixDomainSocketPath())); + try { + if (!getUseInheritedChannel() && serverSock != null) { + // Close server socket + serverSock.close(); + } + serverSock = null; + } finally { + if (getUnixDomainSocketPath() != null && getBindState().wasBound()) { + Files.delete(Paths.get(getUnixDomainSocketPath())); + } } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org