cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jasobr...@apache.org
Subject cassandra git commit: Race condition when closing stream sessions
Date Thu, 07 Sep 2017 23:46:40 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk bab76eba9 -> 83822d12d


Race condition when closing stream sessions

patch by jasobrown; reviewed by Blake Eggleston for CASSANDRA-13852


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/83822d12
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/83822d12
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/83822d12

Branch: refs/heads/trunk
Commit: 83822d12d87dcb3aaad2b1e670e57ebef4ab1c36
Parents: bab76eb
Author: Jason Brown <jasedbrown@gmail.com>
Authored: Wed Sep 6 17:37:24 2017 -0700
Committer: Jason Brown <jasedbrown@gmail.com>
Committed: Thu Sep 7 16:45:23 2017 -0700

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../async/RebufferingByteBufDataInputPlus.java  |  8 +++---
 .../RebufferingByteBufDataInputPlusTest.java    | 28 ++++++++++++++++++++
 3 files changed, 34 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/83822d12/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 0175992..077fd7f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 4.0
+ * Race condition when closing stream sessions (CASSANDRA-13852)
  * NettyFactoryTest is failing in trunk on macOS (CASSANDRA-13831)
  * Allow changing log levels via nodetool for related classes (CASSANDRA-12696)
  * Add stress profile yaml with LWT (CASSANDRA-7960)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/83822d12/src/java/org/apache/cassandra/net/async/RebufferingByteBufDataInputPlus.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/net/async/RebufferingByteBufDataInputPlus.java
b/src/java/org/apache/cassandra/net/async/RebufferingByteBufDataInputPlus.java
index 580bc03..1f32aa8 100644
--- a/src/java/org/apache/cassandra/net/async/RebufferingByteBufDataInputPlus.java
+++ b/src/java/org/apache/cassandra/net/async/RebufferingByteBufDataInputPlus.java
@@ -165,14 +165,16 @@ public class RebufferingByteBufDataInputPlus extends RebufferingInputStream
impl
      * {@inheritDoc}
      *
      * As long as this method is invoked on the consuming thread the returned value will
be accurate.
+     *
+     * @throws EOFException thrown when no bytes are buffered and {@link #closed} is true.
      */
     @Override
     public int available() throws EOFException
     {
-        if (closed)
-            throw new EOFException();
+       final int availableBytes = queuedByteCount.get() + (buffer != null ? buffer.remaining()
: 0);
 
-       final  int availableBytes = queuedByteCount.get() + (buffer != null ? buffer.remaining()
: 0);
+        if (availableBytes == 0 && closed)
+            throw new EOFException();
 
         if (!channelConfig.isAutoRead() && availableBytes < lowWaterMark)
             channelConfig.setAutoRead(true);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/83822d12/test/unit/org/apache/cassandra/net/async/RebufferingByteBufDataInputPlusTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/net/async/RebufferingByteBufDataInputPlusTest.java
b/test/unit/org/apache/cassandra/net/async/RebufferingByteBufDataInputPlusTest.java
index 4968196..2961d9a 100644
--- a/test/unit/org/apache/cassandra/net/async/RebufferingByteBufDataInputPlusTest.java
+++ b/test/unit/org/apache/cassandra/net/async/RebufferingByteBufDataInputPlusTest.java
@@ -123,4 +123,32 @@ public class RebufferingByteBufDataInputPlusTest
         ByteBuffer buf = ByteBuffer.allocate(1);
         inputPlus.read(buf);
     }
+
+    @Test (expected = EOFException.class)
+    public void available_closed() throws EOFException
+    {
+        inputPlus.markClose();
+        inputPlus.available();
+    }
+
+    @Test
+    public void available_HappyPath() throws EOFException
+    {
+        int size = 4;
+        buf = channel.alloc().heapBuffer(size);
+        buf.writerIndex(size);
+        inputPlus.append(buf);
+        Assert.assertEquals(size, inputPlus.available());
+    }
+
+    @Test
+    public void available_ClosedButWithBytes() throws EOFException
+    {
+        int size = 4;
+        buf = channel.alloc().heapBuffer(size);
+        buf.writerIndex(size);
+        inputPlus.append(buf);
+        inputPlus.markClose();
+        Assert.assertEquals(size, inputPlus.available());
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Mime
View raw message