From 2541d5acfd2c10a0225054b6263796479a417e7d Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Wed, 3 Dec 2014 10:06:26 +0000 Subject: [PATCH] HCOLL-229 fix to -stateless client : Terminated thread causes next thread to read the other threads message --- .../chronicle/map/StatelessChronicleMap.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java index b73bac2d4..afc71c411 100644 --- a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java @@ -938,9 +938,6 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon // send out all the bytes send(bytes, timeoutTime); - bytes.clear(); - bytes.buffer().clear(); - return blockingFetch(timeoutTime, transactionId); } catch (java.nio.channels.ClosedChannelException | ClosedConnectionException e) { checkTimeout(timeoutTime); @@ -963,6 +960,9 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon private Bytes blockingFetch(long timeoutTime, long transactionId) throws IOException { + bytes.clear(); + bytes.buffer().clear(); + // the number of bytes in the response final int size = receive(SIZE_OF_SIZE, timeoutTime).readInt(); @@ -982,9 +982,15 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon final boolean isException = bytes.readBoolean(); final long inTransactionId = bytes.readLong(); - if (inTransactionId != transactionId) - throw new IllegalStateException("the received transaction-id=" + inTransactionId + - ", does not match the expected transaction-id=" + transactionId); + if (inTransactionId != transactionId) { + LOG.error("", new IllegalStateException("Skipped Message with transaction-id=" + + inTransactionId + + ", this can occur when you have another thread which has called the " + + "stateless client and terminated abruptly before the message has been " + + "returned from the server")); + + blockingFetch(timeoutTime,transactionId); + } if (isException) { Throwable throwable = (Throwable) bytes.readObject();