Skip to content

Commit

Permalink
[bosesoundtouch] fix possible resource leak (openhab#8031)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan N. Klug <[email protected]>
Signed-off-by: MPH80 <[email protected]>
  • Loading branch information
J-N-K authored and MPH80 committed Aug 3, 2020
1 parent 9b1404d commit 43989d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion bundles/org.openhab.binding.bosesoundtouch/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -93,6 +94,8 @@ public class BoseSoundTouchHandler extends BaseThingHandler implements WebSocket
private PresetContainer presetContainer;
private BoseStateDescriptionOptionProvider stateOptionProvider;

private Future<?> sessionFuture;

/**
* Creates a new instance of this class for the {@link Thing}.
*
Expand Down Expand Up @@ -423,7 +426,7 @@ private synchronized void openConnection() {
request.setSubProtocols("gabbo");
client.setStopTimeout(1000);
client.start();
client.connect(this, new URI(wsUrl), request);
sessionFuture = client.connect(this, new URI(wsUrl), request);
} catch (Exception e) {
onWebSocketError(e);
}
Expand All @@ -439,7 +442,10 @@ private synchronized void closeConnection() {
}
session = null;
}
if (client != null) {
if (sessionFuture != null && !sessionFuture.isDone()) {
sessionFuture.cancel(true);
}
if (client != null && client.isStarted()) {
try {
client.stop();
client.destroy();
Expand Down

0 comments on commit 43989d9

Please sign in to comment.