hangc0276 commented on code in PR #4293:
URL: https://github.com/apache/bookkeeper/pull/4293#discussion_r1614962357


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/util/ByteBufList.java:
##########
@@ -286,19 +286,29 @@ public void write(ChannelHandlerContext ctx, Object msg, 
ChannelPromise promise)
             if (msg instanceof ByteBufList) {
                 ByteBufList b = (ByteBufList) msg;
 
-                try {
-                    // Write each buffer individually on the socket. The 
retain() here is needed to preserve the fact
-                    // that ByteBuf are automatically released after a write. 
If the ByteBufPair ref count is increased
-                    // and it gets written multiple times, the individual 
buffers refcount should be reflected as well.
-                    int buffersCount = b.buffers.size();
-                    for (int i = 0; i < buffersCount; i++) {
-                        ByteBuf bx = b.buffers.get(i);
-                        // Last buffer will carry on the final promise to 
notify when everything was written on the
-                        // socket
-                        ctx.write(bx.retainedDuplicate(), i == (buffersCount - 
1) ? promise : ctx.voidPromise());
+                ChannelPromise compositePromise = ctx.newPromise();
+                compositePromise.addListener(future -> {
+                    // release the ByteBufList after the write operation is 
completed
+                    ReferenceCountUtil.safeRelease(b);

Review Comment:
   Use `ReferenceCountUtil.relesse(b)` to expose potential exceptions in 
release the ByteBufList?



-- 
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