diff --git a/src/main/java/org/java_websocket/client/WebSocketClient.java b/src/main/java/org/java_websocket/client/WebSocketClient.java index 4277c2209..893c8afbf 100644 --- a/src/main/java/org/java_websocket/client/WebSocketClient.java +++ b/src/main/java/org/java_websocket/client/WebSocketClient.java @@ -343,10 +343,12 @@ private void reset() { closeBlocking(); if (writeThread != null) { this.writeThread.interrupt(); + this.writeThread.join(); this.writeThread = null; } if (connectReadThread != null) { this.connectReadThread.interrupt(); + this.connectReadThread.join(); this.connectReadThread = null; } this.draft.reset(); @@ -505,6 +507,14 @@ public void run() { throw e; } + if (writeThread != null) { + writeThread.interrupt(); + try { + writeThread.join(); + } catch (InterruptedException e) { + /* ignore */ + } + } writeThread = new Thread(new WebsocketWriteThread(this)); writeThread.start(); @@ -523,7 +533,6 @@ public void run() { onError(e); engine.closeConnection(CloseFrame.ABNORMAL_CLOSE, e.getMessage()); } - connectReadThread = null; } private void upgradeSocketToSSL() @@ -801,7 +810,6 @@ public void run() { handleIOException(e); } finally { closeSocket(); - writeThread = null; } }