HCOLL-229 fix to -stateless client : Terminated thread causes next thread to read the other threads message

This commit is contained in:
Rob Austin
2014-12-03 10:06:26 +00:00
parent 81082aab62
commit 2541d5acfd
@@ -938,9 +938,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, 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<K, V> implements ChronicleMap<K, V>, 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<K, V> implements ChronicleMap<K, V>, 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();