From 85b4999980f8cfbbf464dfe6663f48d182c11e87 Mon Sep 17 00:00:00 2001 From: PhilipRoman Date: Wed, 1 Nov 2023 16:55:44 +0200 Subject: [PATCH] Fix multiple issues related to reconnect --- .../org/java_websocket/client/WebSocketClient.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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; } }