[shelly] Always try to stop WebSocketClient (#15721)

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>
This commit is contained in:
Wouter Born 2023-10-10 09:44:37 +02:00
parent 04bbbbbd09
commit d64dc9a046
No known key found for this signature in database
GPG Key ID: A58E5C231E0E72B5
2 changed files with 4 additions and 10 deletions

View File

@ -141,12 +141,10 @@ 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();
}
}
}
@Override
public boolean isInitialized() {
@ -1217,10 +1215,8 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac
}
private void disconnect() {
if (rpcSocket.isConnected()) {
rpcSocket.disconnect();
}
}
public Shelly2RpctInterface getRpcHandler() {
return this;

View File

@ -211,9 +211,7 @@ public class Shelly2RpcSocket {
s.close(StatusCode.NORMAL, "Socket closed");
session = null;
}
if (client.isStarted()) {
client.stop();
}
} catch (Exception e) {
if (e.getCause() instanceof InterruptedException) {
logger.debug("{}: Unable to close socket - interrupted", thingName); // e.g. device was rebooted