You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by gu...@apache.org on 2021/09/06 09:04:47 UTC

[dubbo] branch 3.0 updated: Run callback in executor (#8668)

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

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


The following commit(s) were added to refs/heads/3.0 by this push:
     new d545d53  Run callback in executor (#8668)
d545d53 is described below

commit d545d535ca6bec022a4bc91179502e9a5f8c5689
Author: GuoHao <gu...@gmail.com>
AuthorDate: Mon Sep 6 17:04:18 2021 +0800

    Run callback in executor (#8668)
---
 .../dubbo/rpc/protocol/tri/UnaryClientStream.java  | 27 ++++++++++++----------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/UnaryClientStream.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/UnaryClientStream.java
index 3f4c782..b16f975 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/UnaryClientStream.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/UnaryClientStream.java
@@ -75,18 +75,21 @@ public class UnaryClientStream extends AbstractClientStream implements Stream {
 
         @Override
         protected void onError(GrpcStatus status) {
-            Response response = new Response(getRequest().getId(), TripleConstant.TRI_VERSION);
-            response.setErrorMessage(status.description);
-            final AppResponse result = new AppResponse();
-            final Metadata trailers = getTrailers() == null ? getHeaders() : getTrailers();
-            result.setException(getThrowable(trailers));
-            result.setObjectAttachments(UnaryClientStream.this.parseMetadataToAttachmentMap(trailers));
-            response.setResult(result);
-            if (!result.hasException()) {
-                final byte code = GrpcStatus.toDubboStatus(status.code);
-                response.setStatus(code);
-            }
-            DefaultFuture2.received(getConnection(), response);
+            // run in callback executor will truncate exception stack and avoid blocking netty's event loop
+            execute(()-> {
+                Response response = new Response(getRequest().getId(), TripleConstant.TRI_VERSION);
+                response.setErrorMessage(status.description);
+                final AppResponse result = new AppResponse();
+                final Metadata trailers = getTrailers() == null ? getHeaders() : getTrailers();
+                result.setException(getThrowable(trailers));
+                result.setObjectAttachments(UnaryClientStream.this.parseMetadataToAttachmentMap(trailers));
+                response.setResult(result);
+                if (!result.hasException()) {
+                    final byte code = GrpcStatus.toDubboStatus(status.code);
+                    response.setStatus(code);
+                }
+                DefaultFuture2.received(getConnection(), response);
+            });
         }
 
         private Throwable getThrowable(Metadata metadata) {