Skip to content

Commit

Permalink
[shelly] Always try to stop WebSocketClient (openhab#15719)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
wborn authored Oct 8, 2023
1 parent bef7744 commit 72622a1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -1217,9 +1215,7 @@ private void reconnect() throws ShellyApiException {
}

private void disconnect() {
if (rpcSocket.isConnected()) {
rpcSocket.disconnect();
}
rpcSocket.disconnect();
}

public Shelly2RpctInterface getRpcHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 72622a1

Please sign in to comment.