XnLemon opened a new pull request, #3395:
URL: https://github.com/apache/dubbo-go/pull/3395

   Description
   
   Fixes #3351
   
   The consumer-side metadata loading pipeline in registry/servicediscovery and 
metadata/client.go lacked defensive handling for several failure modes:
   
   Problems fixed:
   
   - No fallback when remote storage fails. If the metadata report was 
unavailable, the consumer silently failed with no attempt to fall back to the 
RPC MetadataService. The fix adds an explicit report → RPC fallback path: if 
the report fails or returns nil metadata, the RPC path is tried before giving 
up.
   - Nil URL produced no error. When a service instance was missing 
MetadataServiceURLParams (protocol/port absent), 
buildStandardMetadataServiceURL returned nil and the nil propagated silently. 
The fix returns a descriptive [Metadata-URL] error immediately.
   - Ambiguous cache key. The metadata cache was keyed only on revision, which 
could collide across different apps or registries. The key is now 
app:registryId:revision.
   - Indistinguishable error logs. Report failures, RPC failures, and 
URL-construction failures all produced similar messages. Each failure stage now 
has a distinct prefix: [Metadata-Report], [Metadata-RPC], [Metadata-URL], 
[Metadata-Fallback].
   - Error chain lost in combined failure. When both report and RPC failed, 
perrors.Errorf("%v") discarded both error chains. Changed to perrors.Wrapf so 
the primary error (rpcErr) remains inspectable via errors.Is/errors.As.
   - Missing context on fallback and local-path errors. The nil-report fallback 
and the local/default RPC path returned bare errors with no indication of which 
app/registry/revision was being fetched. Both now wrap the error with that 
context.
   
   Files changed:
   - registry/servicediscovery/service_instances_changed_listener_impl.go — 
fallback logic, cache key, nil guards, error context
   - metadata/client.go — nil URL guard, perrors.Wrapf for RPC errors, ctx 
parameter marked unused with TODO
   
   ---
   修复了 registry/servicediscovery 和 metadata/client.go 中消费侧元数据加载流水线的若干防御性缺陷:
   
   修复内容:
   
   - remote 存储失败时无兜底。 若 metadata report 不可用,消费方会直接失败,不会尝试回退到 RPC 
MetadataService。修复后新增了显式的 report → RPC fallback 路径:report 失败或返回 nil 时,均会尝试 RPC 
再返回错误。
   - nil URL 不报错。 服务实例缺少 
MetadataServiceURLParams(协议/端口为空)时,buildStandardMetadataServiceURL 会静默返回 nil 
并向上传播。修复后立即返回带 [Metadata-URL] 前缀的描述性错误。
   - 缓存键歧义。 元数据缓存仅以 revision 作为键,在多应用/多注册中心场景下存在碰撞风险。现已改为三维复合键 
app:registryId:revision。
   - 日志无法区分错误来源。 report 失败、RPC 失败、URL 
构建失败三类错误的日志格式几乎相同。现在每个阶段都有独立前缀:[Metadata-Report]、[Metadata-RPC]、[Metadata-URL]、[Metadata-Fallback]。
   - 组合失败时错误链丢失。 当 report 和 RPC 同时失败时,perrors.Errorf("%v") 
会将两个错误都拍平成字符串,调用方无法使用 errors.Is/errors.As。修复后改用 perrors.Wrapf,保留了 rpcErr 的完整错误链。
   - fallback 和 local 路径缺少上下文。 nil-report fallback 路径和 local/default RPC 路径返回裸 
error,没有携带 app/registry/revision 信息。修复后两处均通过 perrors.Wrapf 补充了该上下文。
   
   涉及文件:
   - registry/servicediscovery/service_instances_changed_listener_impl.go — 
fallback 逻辑、缓存键、nil 守卫、错误上下文
   - metadata/client.go — nil URL 守卫、perrors.Wrapf 替换、ctx 参数标记为未使用并添加 TODO
   
   ---
   Checklist
   
   - [x] I confirm the target branch is develop
   - [x] Code has passed local testing
   - [x] I have added tests that prove my fix is effective or that my feature 
works
   
   Tests added / updated:
   - TestGetMetadataInfo_CacheKeyFormat — verifies the composite 
app:registry:revision cache key
   - TestGetMetadataInfo_LocalStorageGoesDirectlyToRPC — verifies local path 
skips report entirely
   - TestGetMetadataInfo_FallbackToRPC — verifies report failure triggers RPC 
fallback; error contains both [Metadata-Fallback] and the RPC cause
   - TestGetMetadataInfo_ReportReturnsNil_RPCSucceeds — verifies (nil, nil) 
from report triggers fallback
   - TestGetMetadataInfo_RPCReturnsNilMetadata — verifies nil-metadata guard in 
RPC result path
   - TestGetMetadataInfo_NilMetadataMap — verifies nil Metadata map on instance 
doesn't panic
   - TestListenerUsesRegistryIdToFetchRemoteMetadata — end-to-end: correct 
per-registry report is selected
   - TestGetMetadataFromRpc_NilURL — asserts nil URL produces a [Metadata-URL] 
error


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to