AlexStocks commented on code in PR #3563:
URL: https://github.com/apache/dubbo-go/pull/3563#discussion_r3718097926
##########
registry/protocol/protocol.go:
##########
@@ -86,15 +86,26 @@ func (proto *registryProtocol) getRegistry(registryUrl
*common.URL) registry.Reg
if namespace != "" {
cacheKey = cacheKey + "?" + constant.NacosNamespaceID + "=" +
namespace
}
- actualReg, _ := proto.registries.LoadOrStore(cacheKey, func() any {
- reg, err := extension.GetRegistry(registryUrl.Protocol,
registryUrl)
- if err != nil {
- logger.Errorf("[Registry] registry cannot connect
successfully, err=%s", err.Error())
- panic(err)
- }
- return reg
- }())
- return actualReg.(registry.Registry)
+ if actualReg, loaded := proto.registries.Load(cacheKey); loaded {
+ return cachedRegistry(actualReg, cacheKey)
+ }
+
+ reg, err := extension.GetRegistry(registryUrl.Protocol, registryUrl)
+ if err != nil {
+ logger.Errorf("[Registry] registry cannot connect successfully,
err=%s", err.Error())
+ panic(err)
+ }
+ actualReg, _ := proto.registries.LoadOrStore(cacheKey, reg)
+ return cachedRegistry(actualReg, cacheKey)
+}
+
+func cachedRegistry(value any, cacheKey string) registry.Registry {
+ reg, ok := value.(registry.Registry)
+ if !ok || reg == nil {
Review Comment:
[P1] 同时拒绝缓存接口中的 typed nil
Go 接口里装着 `(*T)(nil)` 时,类型断言会成功且接口本身不等于 nil,因此这里的防御仍会把 typed-nil registry
当成有效值返回;同一 PR 新增的 `registry/directory.cachedInvoker` 也有相同问题。隔离 Linux
探针中,前者返回了伪非 nil `registry.Registry`,后者通过校验后在 `toGroupInvokers ->
invoker.GetURL()` 稳定 SIGSEGV。这些 helper
正是为不可信缓存值替代直接断言而新增的,不能留下另一种可崩溃的非法值。请用一个同时检查 nil-able 动态值的公共
helper(或对具体接口提供安全判空)覆盖这两个缓存入口,并补 typed-nil registry/invoker 回归测试。
--
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]