Skip to content

Commit

Permalink
fix possible resource leak (openhab#8035)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
  • Loading branch information
J-N-K authored and markus7017 committed Sep 18, 2020
1 parent 429c80c commit 819b2aa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion bundles/org.openhab.binding.valloxmv/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 @@ -25,6 +25,7 @@
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.eclipse.jetty.websocket.api.Session;
Expand Down Expand Up @@ -81,18 +82,23 @@ public ValloxMVWebSocket(WebSocketClient webSocketClient, ValloxMVHandler voHand
}

public void request(ChannelUID channelUID, String updateState) {
Future<?> sessionFuture = null;
try {
socket = new ValloxMVWebSocketListener(channelUID, updateState);

ClientUpgradeRequest request = new ClientUpgradeRequest();
logger.debug("Connecting to: {}", destUri);
client.connect(socket, destUri, request);
sessionFuture = client.connect(socket, destUri, request);
socket.awaitClose(2, TimeUnit.SECONDS);
} catch (InterruptedException | IOException e) {
connectionError(e);
} catch (Exception e) {
logger.debug("Unexpected error");
connectionError(e);
} finally {
if (sessionFuture != null && !sessionFuture.isDone()) {
sessionFuture.cancel(true);
}
}
}

Expand Down

0 comments on commit 819b2aa

Please sign in to comment.