]> git.basschouten.com Git - openhab-addons.git/commitdiff
[shelly] Always try to stop WebSocketClient (#15719)
authorWouter Born <github@maindrain.net>
Sun, 8 Oct 2023 09:28:10 +0000 (11:28 +0200)
committerGitHub <noreply@github.com>
Sun, 8 Oct 2023 09:28:10 +0000 (11:28 +0200)
If the client is not stopped it will not be garbage collected because the ShutdownThread keeps a reference to the client so it can be stopped on shutdowns.

See: https://github.com/eclipse/jetty.project/blob/jetty-9.4.x/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java#L420-L433

Signed-off-by: Wouter Born <github@maindrain.net>
bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java
bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2RpcSocket.java

index f25188faf17e778806eb0fcd0b5df1293884d162..c1a9b67f84878c33ce25ebdf164e762272e0cb32 100644 (file)
@@ -141,10 +141,8 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac
             rpcSocket.addMessageHandler(this);
             initialized = true;
         } else {
-            if (rpcSocket.isConnected()) {
-                logger.debug("{}: Disconnect Rpc Socket on initialize", thingName);
-                disconnect();
-            }
+            logger.debug("{}: Disconnect Rpc Socket on initialize", thingName);
+            disconnect();
         }
     }
 
@@ -1217,9 +1215,7 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac
     }
 
     private void disconnect() {
-        if (rpcSocket.isConnected()) {
-            rpcSocket.disconnect();
-        }
+        rpcSocket.disconnect();
     }
 
     public Shelly2RpctInterface getRpcHandler() {
index 06159751ecd9c4b82c379136e657e4eadd9f7a37..faff2738ee27ef412aebf3579b567ea1eb3e4ec1 100644 (file)
@@ -211,9 +211,7 @@ public class Shelly2RpcSocket {
                 s.close(StatusCode.NORMAL, "Socket closed");
                 session = null;
             }
-            if (client.isStarted()) {
-                client.stop();
-            }
+            client.stop();
         } catch (Exception e) {
             if (e.getCause() instanceof InterruptedException) {
                 logger.debug("{}: Unable to close socket - interrupted", thingName); // e.g. device was rebooted