zhouxinyu commented on code in PR #4446:
URL: https://github.com/apache/rocketmq/pull/4446#discussion_r894436028


##########
remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingAbstract.java:
##########
@@ -200,43 +245,79 @@ public void processRequestCommand(final 
ChannelHandlerContext ctx, final Remotin
                 public void run() {
                     try {
                         String remoteAddr = 
RemotingHelper.parseChannelRemoteAddr(ctx.channel());
+                        final HandlerContext handlerContext = new 
HandlerContextAdaptor();
+                        final CompletableFuture<RemotingCommand> 
responseFuture = new CompletableFuture<>();
+                        if (Decision.STOP == 
NettyRemotingAbstract.this.preHandle(handlerContext, cmd, responseFuture)) {
+                            if (cmd.isOnewayRPC()) {
+                                return;
+                            }
+                            // Write response back to clients, which normally 
explains why the associated request
+                            // fails handler chain.
+                            RemotingCommand response;
+                            if (responseFuture.isDone()) {
+                                response = responseFuture.get();
+                            } else {
+                                final String message = "A handle is 
incorrectly implemented. " +
+                                        "It stopped the handler chain without 
setting ResponseFuture";
+                                log.warn(message);
+                                response = 
RemotingCommand.createResponseCommand(RemotingSysResponseCode.SYSTEM_ERROR,
+                                        message);
+                            }
+                            response.setOpaque(opaque);
+                            ctx.writeAndFlush(response);
+                            return;
+                        }
+                        // TODO: Remove the following line when RPC Hook 
reaches end of life.
                         doBeforeRpcHooks(remoteAddr, cmd);

Review Comment:
   How about wrapping registered RpcHooks with a default `Handler` 
implementation which regards exception as `STOP`?



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