From: Wouter Born Date: Sun, 8 Oct 2023 09:28:10 +0000 (+0200) Subject: [shelly] Always try to stop WebSocketClient (#15719) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=72622a1409d143915b912de538083cf6bc7e1cc9;p=openhab-addons.git [shelly] Always try to stop WebSocketClient (#15719) 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 --- diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java index f25188faf1..c1a9b67f84 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java @@ -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() { diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2RpcSocket.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2RpcSocket.java index 06159751ec..faff2738ee 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2RpcSocket.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2RpcSocket.java @@ -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