szetszwo commented on code in PR #955:
URL: https://github.com/apache/ratis/pull/955#discussion_r1376632033


##########
ratis-common/src/main/java/org/apache/ratis/util/ReferenceCountedObject.java:
##########
@@ -81,8 +86,11 @@ static <V> ReferenceCountedObject<V> wrap(V value, Runnable 
retainMethod, Runnab
 
       @Override
       public V get() {
-        if (count.get() < 0) {
+        final int previous = count.get();
+        if (previous < 0) {
           throw new IllegalStateException("Failed to get: object has already 
been completely released.");
+        } else if (previous == 0) {

Review Comment:
   @ivandika3 , Sorry that this change is causing test failures for DataStream 
tests.  Could you include the following fix?
   ```java
   +++ 
b/ratis-netty/src/main/java/org/apache/ratis/netty/server/DataStreamManagement.java
   @@ -325,10 +325,13 @@ public class DataStreamManagement {
        long byteWritten = 0;
        for (ByteBuffer buffer : buf.nioBuffers()) {
          final ReferenceCountedObject<ByteBuffer> wrapped = 
ReferenceCountedObject.wrap(buffer, buf::retain, buf::release);
   +      wrapped.retain();
          try {
            byteWritten += channel.write(wrapped);
          } catch (Throwable t) {
            throw new CompletionException(t);
   +      } finally {
   +        wrapped.release();
          }
        }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to