成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

一個 Dubbo Triple 協議的 "Bug"

開發 前端
在使用 Dubbo-go 客戶端調用 Dubbo-java 服務時,發現通過 context 設置的 attachment 中,"remote.application" 鍵值對在服務端無法獲取,而 "remote.application1" 和 "remote.application2" 可以正常獲取。

問題描述

近期涂鴉智能的筒子反饋:dubbogo 客戶端使用 Triple 協議發往 dubbo (Java) 服務端的某些 attachment 會發送丟失現象,并報了 issue:

https://github.com/apache/dubbo-go/issues/2752

問題簡述:服務端無法從附件中獲取鍵名為 remote.application 的值。

具體來說,在使用 Dubbo-go 客戶端調用 Dubbo-java 服務時,發現通過 context 設置的 attachment 中,"remote.application" 鍵值對在服務端無法獲取,而 "remote.application1" 和 "remote.application2" 可以正常獲取。

這里先給出結論:這不是一個 bug,之所以 attachment 中 key 為 "remote.application" 的 item 在 dubbo server 端被過濾掉,是因為該 key 是 dubbo(Java) attachment 中的保留字段,不允許用戶使用。

下面給出問題復現,以及問題分析過程。

環境準備

  • 服務端:Dubbo-Java v3.3.0
  • 客戶端:Dubbo-go v3.2.0-rc2
  • 協議:triple
  • 注冊中心:Zookeeper

參考:https://github.com/apache/dubbo-go-samples

  • 代碼:Dubbo java and go interoperability, protobuf and triple protocol
  • 文檔:基于 protobuf 實現 triple 協議互通(適用于兩邊都用 protobuf 開發的場景)

Client 端

先下載 dubbo-go-samples 工程,在工程根目錄下執行如下命令,以更新 dubbo-go-sample 依賴的 dubbogo 版本。

$ go get dubbo.apache.org/dubbo-go/v3@v3.2.0-rc2

java_interop/protobuf-triple/go/go-client/cmd/client.go:

package main


import (
	"context"
	"dubbo.apache.org/dubbo-go/v3/client"
	"dubbo.apache.org/dubbo-go/v3/common/constant"
	_ "dubbo.apache.org/dubbo-go/v3/imports"
	greet "github.com/apache/dubbo-go-samples/java_interop/protobuf-triple/go/proto"
	"github.com/dubbogo/gost/log/logger"
)
func main() {
	cli, err := client.NewClient(
		client.WithClientURL("127.0.0.1:50052"),
	)
	if err != nil {
		panic(err) // If there's an error, it's handled immediately by panicking.
	}
	svc, err := greet.NewGreeter(cli)
	if err != nil {
		panic(err) // Same here, handle the error immediately.
	}
	ctx := context.Background()
	ctx = context.WithValue(ctx, constant.AttachmentKey, map[string]interface{}{
		"remote.application":  "appname",
		"remote.application1": "appname",
		"remote.application2": "appname",
	})
	resp, err := svc.SayHello(ctx, &greet.HelloRequest{Name: "hello world"})
	if err != nil {
		logger.Error(err)
		return // Now, we explicitly handle the error by logging it and then returning from the function.
	}
	logger.Infof("Greet response: %s", resp.Message)
}

Server 端

java_interop/protobuf-triple/java/java-server/pom.xml:

<properties>
    <maven.compiler.source>8</maven.compiler.source>
    <maven.compiler.target>8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <dubbo.version>3.3.0</dubbo.version>
</properties>

java_interop/protobuf-triple/java/java-server/src/main/java/org/apache/dubbo/sample/GreeterImpl.java:

package org.apache.dubbo.sample;
import com.alibaba.fastjson2.JSON;
import org.apache.dubbo.rpc.RpcContext;

import java.util.Map;

public class GreeterImpl extends DubboGreeterTriple.GreeterImplBase {
    @Override
    public HelloReply sayHello(HelloRequest request) {
        Map<String, Object> serverAttachments = RpcContext.getServerAttachment().getObjectAttachments();
        System.out.println("ContextService serverAttachments:" + JSON.toJSONString(serverAttachments));
        return HelloReply.newBuilder()
                .setMessage(request.getName())
                .build();
    }
}

運行

Go client 調用 java server

  • java-server 目錄中:
$ ./run.sh
...
Dubbo triple java server started
  • go-client 目錄中:
$ go run cmd/client.go
  • 結果輸出

服務端:

2月 12, 2025 6:26:30 下午 org.apache.dubbo.common.logger.jdk.JdkLogger info
信息:  [DUBBO] The connection [id: 0x156ed855, L:/127.0.0.1:50052 - R:/127.0.0.1:56961] of 127.0.0.1:56961 -> 127.0.0.1:50052 is established., dubbo version: 3.3.0, current host: 10.60.200.103
ContextService serverAttachments:{"retries":"","remote.application1":"appname","remote.application2":"appname"}
2月 12, 2025 6:26:30 下午 org.apache.dubbo.common.logger.jdk.JdkLogger info
信息:  [DUBBO] The connection [id: 0x156ed855, L:/127.0.0.1:50052 ! R:/127.0.0.1:56961] of 127.0.0.1:56961 -> 127.0.0.1:50052 is disconnected., dubbo version: 3.3.0, current host: 10.60.200.103
2月 12, 2025 6:26:30 下午 org.apache.dubbo.common.logger.jdk.JdkLogger warn
警告:  [DUBBO] All clients has disconnected from /127.0.0.1:50052. You can graceful shutdown now., dubbo version: 3.3.0, current host: 10.60.200.103, error code: 99-0. This may be caused by unknown error in remoting module, go to https://dubbo.apache.org/faq/99/0 to find instructions. 
2月 12, 2025 6:26:30 下午 org.apache.dubbo.common.logger.jdk.JdkLogger info
信息:  [DUBBO] The connection [id: 0x156ed855, L:/127.0.0.1:50052 ! R:/127.0.0.1:56961] of 127.0.0.1:56961 -> 127.0.0.1:50052 is disconnected., dubbo version: 3.3.0, current host: 10.60.200.103

客戶端:

2025-02-12 18:26:29	INFO	logger/logging.go:42	URL specified explicitly 127.0.0.1:50052
2025-02-12 18:26:30	INFO	logger/logging.go:42	[TRIPLE Protocol] Refer service: tri://127.0.0.1:50052/org.apache.dubbo.sample.Greeter?app.version=&application=dubbo.io&async=false&bean.name=org.apache.dubbo.sample.Greeter&cluster=failover&config.tracing=&environment=&generic=&group=&interface=org.apache.dubbo.sample.Greeter&loadbalance=&metadata-type=local&module=sample&name=dubbo.io&organization=dubbo-go&owner=dubbo-go&peer=true&provided-by=&reference.filter=cshutdown?istry.role=0&release=dubbo-golang-3.2.0&remote.timestamp=&retries=&serialization=protobuf&side=consumer&sticky=false×tamp=1739355989&version=
2025-02-12 18:26:30	INFO	logger/logging.go:42	Greet response: hello world

注意到 java-server 無法從 go-server 傳遞的 attachment 獲取 "remote.application" 鍵。

問題分析

在這個場景中涉及到 ClientAttachment 和 ServerAttachment:

  • ClientAttachmen:Go 客戶端寫入參數
  • ServerAttachment:Java 服務端讀取參數

調用流程:

  • client 端:Method Invoke 發起調用 $\rightarrow$ 寫入 RpcClientAttachment $\rightarrow$ 封裝進 Invocation $\rightarrow$ 序列化傳輸
  • server 端:解析 Invocation $\rightarrow$ 生成 Method Invoke 參數和 RpcServerAttachment $\rightarrow$ 真實調用

$\rightarrow$ 處理后生成 Result(包含 Response 和 Context)$\rightarrow$ 序列化返回。

參考 官方文檔:

圖片

Triple 協議會將 attachment 轉換為 HTTP header 傳輸,使用 Wireshark 抓包分析,確認 "remote.application" 確實被正確封裝在 HTTP header 中,說明 Go 客戶端的 ClientAttachment → Invocation → 網絡傳輸鏈路是正常的。

關注 Java 服務端的 org.apache.dubbo.rpc.protocol.tri.h12.AbstractServerTransportListener 服務端是請求處理的核心類,負責接收和處理 HTTP 請求,并構建 RPC 調用對象。

// AbstractServerTransportListener.java
protected RpcInvocation buildRpcInvocation(RpcInvocationBuildContext context) {
    // ...
    // 關鍵轉換點:將 HTTP Header 轉為 RPC Attachment
    inv.setObjectAttachments(StreamUtils.toAttachments(httpMetadata.headers()));
    // ...
}

調用 StreamUtils.toAttachments() 之前,Header 中是包含 "remote.application" 的。

調用 StreamUtils.toAttachments() 之后,RpcInvocation 類型對象 inv 的成員變量 Map<String,Object>attachments 不包含 "remote.application"。

StreamUtils#toAttachments(HttpHeaders headers):

/**
 * Parse and convert headers to attachments. Ignore Http2 PseudoHeaderName and internal name
 *
 * @param headers the headers
 * @return the attachments
 */
public static Map<String, Object> toAttachments(HttpHeaders headers) {
    if (headers == null) {
        return Collections.emptyMap();
    }
    Map<String, Object> attachments = CollectionUtils.newHashMap(headers.size());
    for (Map.Entry<CharSequence, String> entry : headers) {
        String key = entry.getKey().toString();
        String value = entry.getValue();
        int len = key.length() - TripleConstants.HEADER_BIN_SUFFIX.length();
        if (len > 0 && TripleConstants.HEADER_BIN_SUFFIX.equals(key.substring(len))) {
            try {
                putAttachment(attachments, key.substring(0, len), value == null ? null : dec
            } catch (Exception e) {
                LOGGER.error(PROTOCOL_FAILED_PARSE, "", "", "Failed to parse response attach
            }
        } else {
            putAttachment(attachments, key, value);
        }
    }
    // try converting upper key
    String converted = headers.getFirst(TripleHeaderEnum.TRI_HEADER_CONVERT.getKey());
    if (converted == null) {
        return attachments;
    }
    String json = TriRpcStatus.decodeMessage(converted);
    Map<String, String> map = JsonUtils.toJavaObject(json, Map.class);
    for (Map.Entry<String, String> entry : map.entrySet()) {
        String key = entry.getKey();
        Object value = attachments.remove(key);
        if (value != null) {
            putAttachment(attachments, entry.getValue(), value);
        }
    }
    return attachments;
}

StreamUtils#putAttachment(Map<String, Object> attachments, String key, Object value):

圖片

進一步查看 TripleHeaderEnum :

圖片

為了防止業務層誤用或覆蓋這個鍵值,Dubbo 將其加入了排除列表,導致即使在 attachment 中設置了這個鍵值對,在轉換時也會被過濾掉。

責任編輯:姜華 來源: dubbogo示土區
相關推薦

2022-04-06 08:47:03

Dubbo服務協議

2009-09-14 17:08:02

WebFormView

2021-10-08 07:50:57

軟件設計程序

2017-10-10 15:14:23

BUGiOS 11蘋果

2024-09-14 14:14:26

Dubbo框架微服務

2014-12-17 09:40:22

dockerLinuxPaaS

2024-04-22 00:00:01

Redis集群

2015-08-24 10:07:13

程序員bug

2019-08-01 12:59:21

Bug代碼程序

2022-06-15 08:14:40

Go線程遞歸

2023-03-13 08:09:03

Protobuffeature分割

2022-05-16 08:42:26

Pandasbug

2024-08-08 08:09:38

2018-06-19 16:04:27

Dubbo應用Java

2011-03-03 21:04:08

bug程序員

2021-09-11 19:00:54

Intro元素MemoryCache

2015-08-19 09:29:35

Git協議編寫

2017-03-22 09:11:45

bugbug賞金計劃眾包項目

2010-11-17 15:43:55

軟件測試Bug

2019-05-23 09:30:22

網絡框架數據
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲 中文 欧美 日韩 在线观看 | 色接久久| 国产美女自拍视频 | 欧美老少妇一级特黄一片 | 亚洲一区二区三区在线视频 | 日日摸日日碰夜夜爽2015电影 | 国产高清美女一级a毛片久久w | 黄色片免费在线观看 | 99久久精品国产一区二区三区 | 精品欧美一区二区中文字幕视频 | 狠狠艹 | 99热热热热 | 羞羞视频免费观 | 伊人久久麻豆 | 国产三区av| 亚洲国产aⅴ成人精品无吗 综合国产在线 | 久久久久久久电影 | 精品国产一区二区久久 | 久久久资源 | 欧美午夜一区 | 特黄毛片| 毛片综合| 伊人免费在线观看 | 国产欧美日韩精品一区二区三区 | 久久精品国产亚洲 | h视频在线观看免费 | 一区二区中文 | 国产h视频 | 日本不卡一区 | 日韩欧美综合 | 夜夜爽99久久国产综合精品女不卡 | 日本人麻豆 | 国产一在线观看 | 久久久久久久久久久久亚洲 | 日韩三区在线观看 | av高清| 精品美女久久久 | 成人在线免费视频 | 精品久久久久久久人人人人传媒 | 国产精品123区 | 白浆在线 |