This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.2 by this push:
     new c8ef10e8a5 Check if return AsyncRpcResult in Filter (#12467)
c8ef10e8a5 is described below

commit c8ef10e8a5cc6d470aa66125887c2d39ded97947
Author: Albumen Kevin <[email protected]>
AuthorDate: Tue Jun 6 19:39:50 2023 +0800

    Check if return AsyncRpcResult in Filter (#12467)
    
    * Check if return AsyncRpcResult in Filter
    
    * Fix compatible
---
 .../org/apache/dubbo/rpc/cluster/filter/FilterChainBuilder.java  | 9 +++++++++
 dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Filter.java | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/FilterChainBuilder.java
 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/FilterChainBuilder.java
index a837724819..815f8821dd 100644
--- 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/FilterChainBuilder.java
+++ 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/FilterChainBuilder.java
@@ -21,6 +21,7 @@ import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.extension.SPI;
 import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
 import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.rpc.AsyncRpcResult;
 import org.apache.dubbo.rpc.BaseFilter;
 import org.apache.dubbo.rpc.Filter;
 import org.apache.dubbo.rpc.Invocation;
@@ -36,6 +37,7 @@ import java.util.List;
 import java.util.stream.Collectors;
 
 import static 
org.apache.dubbo.common.constants.LoggerCodeConstants.CLUSTER_EXECUTE_FILTER_EXCEPTION;
+import static 
org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR;
 import static org.apache.dubbo.common.extension.ExtensionScope.APPLICATION;
 
 @SPI(value = "default", scope = APPLICATION)
@@ -294,6 +296,7 @@ public interface FilterChainBuilder {
 
     @Experimental("Works for the same purpose as FilterChainNode, replace 
FilterChainNode with this one when proved stable enough")
     class CopyOfFilterChainNode<T, TYPE extends Invoker<T>, FILTER extends 
BaseFilter> implements Invoker<T> {
+        private static final ErrorTypeAwareLogger LOGGER = 
LoggerFactory.getErrorTypeAwareLogger(CopyOfFilterChainNode.class);
         TYPE originalInvoker;
         Invoker<T> nextNode;
         FILTER filter;
@@ -329,6 +332,12 @@ public interface FilterChainBuilder {
             try {
                 InvocationProfilerUtils.enterDetailProfiler(invocation, () -> 
"Filter " + filter.getClass().getName() + " invoke.");
                 asyncResult = filter.invoke(nextNode, invocation);
+                if (!(asyncResult instanceof AsyncRpcResult)) {
+                    String msg = "The result of filter invocation must be 
AsyncRpcResult. (If you want to recreate a result, please use 
AsyncRpcResult.newDefaultAsyncResult.) " +
+                        "Filter class: " + filter.getClass().getName() + ". 
Result class: " + asyncResult.getClass().getName() + ".";
+                    LOGGER.error(INTERNAL_ERROR, "", "", msg);
+                    throw new RpcException(msg);
+                }
             } catch (Exception e) {
                 InvocationProfilerUtils.releaseDetailProfiler(invocation);
                 if (filter instanceof ListenableFilter) {
diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Filter.java 
b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Filter.java
index fa33393123..c196baa517 100644
--- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Filter.java
+++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Filter.java
@@ -35,7 +35,7 @@ public interface Filter extends org.apache.dubbo.rpc.Filter {
             new Invocation.CompatibleInvocation(invocation));
 
         if (invokeResult instanceof Result.CompatibleResult) {
-            return invokeResult;
+            return ((Result.CompatibleResult) invokeResult).getDelegate();
         }
 
         AsyncRpcResult asyncRpcResult = 
AsyncRpcResult.newDefaultAsyncResult(invocation);

Reply via email to