From efd4b4b771098f66e830f6f8e0dd78dc5805fa5f Mon Sep 17 00:00:00 2001 From: Manevolent Date: Mon, 22 Oct 2018 13:40:43 -0400 Subject: [PATCH] Reorganizing the removal of awaiting commands and so forth in hopes that lock-ups don't happen on reconnect. --- .../client/LocalTeamspeakClientSocket.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java b/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java index 2a2f23d..c5b09e7 100644 --- a/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java +++ b/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java @@ -359,8 +359,16 @@ public class LocalTeamspeakClientSocket // Free stuff serverId = null; - awaitingCommands.clear(); - acceptingReturnCode = 0; + + + synchronized (commandSendLock) { + for (Integer id : new ArrayList<>(awaitingCommands.keySet())) { + ClientCommandResponse response = awaitingCommands.get(id); + response.completeFailure(new IOException("client disconnected")); + } + awaitingCommands.clear(); + calculateAcceptingReturnCode(); + } setOption("client.hostname", remote.getHostString()); @@ -604,11 +612,6 @@ public class LocalTeamspeakClientSocket private void handleComplete(SingleCommand command) throws IOException, TimeoutException { try { - synchronized (commandSendLock) { - awaitingCommands.remove(returnCode); - acceptingReturnCode = calculateAcceptingReturnCode(); - } - int errorId = Integer.parseInt(command.get("id").getValue()); switch (errorId) { @@ -621,7 +624,11 @@ public class LocalTeamspeakClientSocket } catch (Throwable e) { completeFailure(e); } finally { - sendNextCommand(); + synchronized (commandSendLock) { + awaitingCommands.remove(getReturnCode()); + acceptingReturnCode = calculateAcceptingReturnCode(); + sendNextCommand(); + } } }