You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2021/01/08 15:51:53 UTC

[tomcat] branch master updated: Make sure the socket is always cleaned up

This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new 9768ef8  Make sure the socket is always cleaned up
9768ef8 is described below

commit 9768ef82f4481c83d25b495fcc959f6d92bbc4a2
Author: remm <re...@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 55356f9..83b9715 100644
--- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
@@ -124,20 +124,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;
+        }
     }
 
 
@@ -586,7 +592,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 2661671..998647c 100644
--- a/java/org/apache/tomcat/util/net/NioEndpoint.java
+++ b/java/org/apache/tomcat/util/net/NioEndpoint.java
@@ -344,13 +344,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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org