Skip to content

fix(registry): remove silent protocol filter in cacheInvoker (#3173)#3263

Closed
MoChengqian wants to merge 3 commits intoapache:mainfrom
MoChengqian:fix-issue-3173
Closed

fix(registry): remove silent protocol filter in cacheInvoker (#3173)#3263
MoChengqian wants to merge 3 commits intoapache:mainfrom
MoChengqian:fix-issue-3173

Conversation

@MoChengqian
Copy link

@MoChengqian MoChengqian commented Mar 17, 2026

描述

#3173
移除 cacheInvoker 中的静默协议过滤

📝 BUG 描述
Go 消费端默认协议是 tri,Java Dubbo 2.x 服务端注册协议是 dubbo,cacheInvoker 里的逻辑需要provider和consumer协议匹配,然而版本更新后协议变化,原逻辑匹配内容变成需要判定 tri == dubbo ,守卫把协议不一致的provider 静默丢弃(未添加日志),导致消费端始终无法看到Java Dubbo 2.x 服务端使用dubbo协议的消费者 。

解决方案
删除 cacheInvoker 里按协议匹配过滤 provider 的条件判断,让所有注册中心发现的 provider 都进入缓存,由后续 MergeURL 保留各自协议完成正确调用

背景

当使用 client.NewClient 创建 Go 消费者时,referenceUrl.Protocol 默认值为 "tri"(Triple 协议)。Java Dubbo 2.x 提供者在 ZooKeeper 中注册时使用 protocol="dubbo"cacheInvoker 中原有的协议校验逻辑:
if url.Protocol == referenceUrl.Protocol || referenceUrl.Protocol == "" {
对每一个 Java 提供者的评估结果均为 false,导致这些提供者被静默地从调用器缓存中移除。消费者始终看到"无可用提供者"的错误,且日志中没有任何错误或警告。

根本原因

在注册中心目录层进行协议过滤是多此一举的。ZooKeeper/Nacos 已经通过 接口 + 分组 + 版本号 对提供者查找进行了范围限定。原有的协议校验是一个过早的预过滤,破坏了跨协议的互操作性。

协议选择由下游处理:MergeURL 保留了提供者的协议字段,而 ProtocolFilterWrapper.Refer 使用该字段查找正确的处理器(例如 DubboProtocol)。目录层不需要进行预过滤。

变更内容

  • registry/directory/directory.go — 移除了 cacheInvoker 中的协议相等性校验;添加了引用此问题的解释性注释。
  • registry/directory/directory_test.go — 新增回归测试 Test_CrossProtocol_ProviderDiscovery_Issue3173:tri 消费者 + dubbo 提供者 → 提供者能被发现,且调用器保留 protocol=dubbo
  • client/options.go — 精简了默认协议赋值处的注释,解释此 bug 的历史原因;移除了任何暗示跨协议缓存是稳定 API 契约的内容。

检查清单

✅ 我确认目标分支是 develop
✅ 代码已通过本地测试
✅ 我已添加证明修复有效的测试用例

…3173)

Go consumer defaults to protocol "tri" while Java Dubbo 2.x providers
register with protocol "dubbo". The protocol equality guard in cacheInvoker
silently discarded mismatched providers, causing "No provider available".

Remove the guard: registry-based discovery already scopes by
interface/group/version, and MergeURL preserves the provider's protocol for
correct downstream invocation.

Add regression test Test_CrossProtocol_ProviderDiscovery_Issue3173.
@sonarqubecloud
Copy link

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.15%. Comparing base (ba17613) to head (f10615d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3263      +/-   ##
==========================================
- Coverage   48.15%   48.15%   -0.01%     
==========================================
  Files         466      466              
  Lines       34048    34047       -1     
==========================================
- Hits        16395    16394       -1     
  Misses      16322    16322              
  Partials     1331     1331              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MoChengqian MoChengqian marked this pull request as ready for review March 17, 2026 07:55
@Alanxtl Alanxtl added ☢️ Bug 3.3.2 version 3.3.2 labels Mar 17, 2026
@Alanxtl Alanxtl linked an issue Mar 17, 2026 that may be closed by this pull request
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.3.2 version 3.3.2 ☢️ Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] 无法从zookeeper上发现服务提供者

3 participants