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

一個 Dubbo Triple 協(xié)議的 "Bug"

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

問題描述

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

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

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

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

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

下面給出問題復現(xiàn),以及問題分析過程。

環(huán)境準備

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

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

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

Client 端

先下載 dubbo-go-samples 工程,在工程根目錄下執(zhí)行如下命令,以更新 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 調(diào)用 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 客戶端寫入?yún)?shù)
  • ServerAttachment:Java 服務端讀取參數(shù)

調(diào)用流程:

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

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

參考 官方文檔:

圖片

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

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

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

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

調(diào)用 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 :

圖片

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

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

2022-04-06 08:47:03

Dubbo服務協(xié)議

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協(xié)議編寫

2017-03-22 09:11:45

bugbug賞金計劃眾包項目

2010-11-17 15:43:55

軟件測試Bug

2019-05-23 09:30:22

網(wǎng)絡框架數(shù)據(jù)
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 综合一区二区三区 | 精品久久久久久亚洲精品 | 久久久久亚洲精品 | 91视频麻豆 | 日本免费黄色 | 国产亚洲精品美女久久久久久久久久 | 黄网站在线观看 | 国产精品久久福利 | 99国产精品99久久久久久粉嫩 | 男女视频在线看 | 中文字幕亚洲精品 | 国产视频综合 | 日本成人久久 | 超碰在线人 | 久久久久久高清 | 国产最新精品视频 | 狠狠做六月爱婷婷综合aⅴ 国产精品视频网 | 日韩一级免费大片 | 精品视频一区二区三区 | 九九免费视频 | 国产精品久久久久久久7777 | 911精品美国片911久久久 | 欧美一区二区三区在线看 | 超碰在线人人 | 自拍偷拍亚洲一区 | 国产午夜视频 | 羞羞视频网站免费观看 | 日韩国产中文字幕 | 日韩视频一区 | 国产真实精品久久二三区 | 国产一区二区小视频 | 久久青草av| 欧美一区2区三区4区公司 | 日韩视频一级 | 九九九国产 | 国产精品高 | 日韩欧美一区二区在线播放 | 九九热国产精品视频 | 一级黄色片在线免费观看 | 亚洲精品免费视频 | 日韩精品|