From 72622a1409d143915b912de538083cf6bc7e1cc9 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Sun, 8 Oct 2023 11:28:10 +0200 Subject: [PATCH] [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 --- .../binding/shelly/internal/api2/Shelly2ApiRpc.java | 10 +++------- .../binding/shelly/internal/api2/Shelly2RpcSocket.java | 4 +--- 2 files changed, 4 insertions(+), 10 deletions(-) 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 f25188faf17e7..c1a9b67f84878 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 void initialize() throws ShellyApiException { 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 @@ private void reconnect() throws ShellyApiException { } 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 06159751ecd9c..faff2738ee27e 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 void disconnect() { 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