[SSHD-878] Clear user-defined client/server/session/channel attributes when entity...
authorLyor Goldstein <lgoldstein@apache.org>
Sun, 30 Dec 2018 12:20:33 +0000 (14:20 +0200)
committerLyor Goldstein <lgoldstein@apache.org>
Sun, 30 Dec 2018 18:52:37 +0000 (20:52 +0200)
CHANGES.md
sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
sshd-core/src/main/java/org/apache/sshd/server/SshServer.java

index eae9bf8..b5a3abe 100644 (file)
 
     * Added `attributeKeys` enumeration method to `AttributeRepository`.
 
+    * In this context, please note that all associated session/channel/client/server attributes
+    are cleared when entity is closed. The clearing usually occurs as after all relevant registered
+    event listeners have been invoked.
+
 * `DEFAULT_PORT` moved from `SshConfigFileReader` to `SshConstants`.
 
 * Moved some session "summary" related definitions from `Session` to `SessionContext` (which `Session` extends).
index e4db27a..b711693 100644 (file)
@@ -426,6 +426,9 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
             if (log.isTraceEnabled()) {
                 log.trace("Stop exception details", e);
             }
+        } finally {
+            // clear the attributes since we close stop the client
+            clearAttributes();
         }
     }
 
index 267d115..8850b8b 100644 (file)
@@ -694,6 +694,8 @@ public abstract class AbstractChannel
         } finally {
             // clear the listeners since we are closing the channel (quicker GC)
             this.channelListeners.clear();
+            // clear the attributes since we close the channel
+            clearAttributes();
         }
 
         IOException err = IoUtils.closeQuietly(getLocalWindow(), getRemoteWindow());
index ed5c15f..f16a881 100644 (file)
@@ -663,6 +663,8 @@ public abstract class AbstractSession extends SessionHelper {
             this.sessionListeners.clear();
             this.channelListeners.clear();
             this.tunnelListeners.clear();
+            // clear the attributes since we close the session
+            clearAttributes();
         }
 
         super.preClose();
index 72ed860..ef129f7 100644 (file)
@@ -351,10 +351,15 @@ public class SshServer extends AbstractFactoryManager implements ServerFactoryMa
             return;
         }
 
-        long maxWait = immediately ? this.getLongProperty(STOP_WAIT_TIME, DEFAULT_STOP_WAIT_TIME) : Long.MAX_VALUE;
-        boolean successful = close(immediately).await(maxWait);
-        if (!successful) {
-            throw new SocketTimeoutException("Failed to receive closure confirmation within " + maxWait + " millis");
+        try {
+            long maxWait = immediately ? this.getLongProperty(STOP_WAIT_TIME, DEFAULT_STOP_WAIT_TIME) : Long.MAX_VALUE;
+            boolean successful = close(immediately).await(maxWait);
+            if (!successful) {
+                throw new SocketTimeoutException("Failed to receive closure confirmation within " + maxWait + " millis");
+            }
+        } finally {
+            // clear the attributes since we close stop the server
+            clearAttributes();
         }
     }