Skip to content

Commit 7212fae

Browse files
committed
Bug: 482928 - MQTT connection not closed if WebSocket closed by server
Closing the pipedOutputStream if an exception is thrown. Signed-off-by: James Sutton <james.sutton@uk.ibm.com>
1 parent 513a77a commit 7212fae

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

  • org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/websocket

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/websocket/WebSocketReceiver.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public void stop() {
6969
if(running) {
7070
running = false;
7171
receiving = false;
72+
closeOutputStream();
7273
if( !Thread.currentThread().equals(receiverThread)) {
7374
try {
7475
// Wait for the thread to finish
@@ -100,12 +101,20 @@ public void run() {
100101
receiving = false;
101102

102103
} catch (IOException ex) {
103-
104+
// Exception occurred whilst reading the stream.
105+
closeOutputStream();
104106
}
105107
}
106108

107109
}
108110

111+
private void closeOutputStream(){
112+
try {
113+
pipedOutputStream.close();
114+
} catch (IOException e) {
115+
}
116+
}
117+
109118

110119
public boolean isRunning() {
111120
return running;

0 commit comments

Comments
 (0)