You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ratis.apache.org by GitBox <gi...@apache.org> on 2020/11/15 07:13:50 UTC

[GitHub] [incubator-ratis] szetszwo commented on a change in pull request #277: RATIS-1150. Return DataStreamException to client

szetszwo commented on a change in pull request #277:
URL: https://github.com/apache/incubator-ratis/pull/277#discussion_r523717815



##########
File path: ratis-netty/src/main/java/org/apache/ratis/netty/server/DataStreamManagement.java
##########
@@ -412,7 +417,11 @@ void read(DataStreamRequestByteBuf request, ChannelHandlerContext ctx,
           }
           buf.release();
           return null;
-        }, executor));
+        }, executor)).exceptionally(exception -> {
+      replyDataStreamException(server, exception, info.getRequest(), request, ctx);
+      buf.release();
+      return null;
+    });

Review comment:
       Use whenComplete(..) and also a try-catch as below:
   ```suggestion
           }, executor)
       ).whenComplete((v, exception) -> {
         try {
           if (exception != null) {
             replyDataStreamException(server, exception, info.getRequest(), request, ctx);
           }
         } finally {
           buf.release();
         }
       });
   ```

##########
File path: ratis-netty/src/main/java/org/apache/ratis/netty/server/DataStreamManagement.java
##########
@@ -412,7 +417,11 @@ void read(DataStreamRequestByteBuf request, ChannelHandlerContext ctx,
           }
           buf.release();

Review comment:
       Remove `buf.release();` and use `whenComplete(..)` below.

##########
File path: ratis-netty/src/main/java/org/apache/ratis/netty/server/DataStreamManagement.java
##########
@@ -371,7 +373,10 @@ void read(DataStreamRequestByteBuf request, ChannelHandlerContext ctx,
       // for peers to start transaction
       final StreamInfo info = streams.get(key);
       composeAsync(info.getPrevious(), executor, v -> startTransaction(info, request, ctx))
-          .thenAccept(v -> buf.release());
+          .thenAccept(v -> buf.release()).exceptionally(exception -> {
+        replyDataStreamException(server, exception, info.getRequest(), request, ctx);
+        return null;
+      });

Review comment:
       Use whenComplete(..) and also a try-catch as below:
   ```suggestion
             .whenComplete((v, exception) -> {
           try {
             if (exception != null) {
               replyDataStreamException(server, exception, info.getRequest(), request, ctx);
             }
           } finally {
             buf.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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org