CAICAIIs opened a new issue, #3177: URL: https://github.com/apache/dubbo-go/issues/3177
### ✅ 验证清单 - [x] 🔍 我已经搜索过 [现有 Issues](https://github.com/apache/dubbo-go/issues),确信这不是重复问题 ### 🚀 Go 版本 1.24.0+ ### 📦 Dubbo-go 版本 v3.3.1 ### 🖥️ 服务端配置 _No response_ ### 💻 客户端配置 _No response_ ### 🌐 协议配置 _No response_ ### 📋 注册中心配置 _No response_ ### 💾 操作系统 🍎 macOS ### 📝 Bug 描述 registry/nacos/registry.go 中的 subscribeUntilSuccess() 函数在订阅失败时会无限重试,但重试循环中没有任何 sleep 或退避机制,导致当 Nacos 服务不可用时,CPU 会 100% 空转。 问题代码位置: registry/nacos/registry.go 第 204 行附近 ```go func (nr *nacosRegistry) subscribeUntilSuccess(url *common.URL, notifyListener registry.NotifyListener) { for { if !nr.IsAvailable() { return } err := nr.subscribe(getSubscribeName(url), notifyListener) if err == nil { return } // 失败后没有任何等待,立即进入下一次循环 } } ``` ### 🔄 重现步骤 1. 启动一个依赖 Nacos 注册中心的 dubbo-go 消费者服务 2. 确保 Nacos 服务正常运行,消费者成功订阅服务 3. 停止 Nacos 服务(模拟 Nacos 宕机或网络不可达) 4. 观察消费者服务的 CPU 使用率 ### ✅ 预期行为 当 Nacos 服务不可用时: - CPU 使用率应保持在较低水平 - 日志应以合理的频率输出(如每分钟几条) - 重试请求不应对 Nacos 服务端造成过大压力 ### ❌ 实际行为 当 Nacos 服务不可用时: - *CPU 使用率飙升到 100%*,持续空转 - 每秒产生数十万次无效重试 - 如果有错误日志,会瞬间产生海量日志,可能撑爆磁盘 - 当 Nacos 恢复时,大量客户端同时重试会造成重试风暴,可能导致 Nacos 再次过载 ### 💡 可能的解决方案 使用 github.com/cenkalti/backoff/v4 库实现指数退避重试: ```go func (nr *nacosRegistry) subscribeUntilSuccess(url *common.URL, notifyListener registry.NotifyListener) { bo := backoff.NewExponentialBackOff() bo.InitialInterval = 1 * time.Second // 首次重试等待 1 秒 bo.MaxInterval = 30 * time.Second // 最大等待 30 秒 bo.MaxElapsedTime = 0 // 永不超时,持续重试 operation := func() error { if !nr.IsAvailable() { return backoff.Permanent(perrors.New("registry unavailable")) } return nr.subscribe(getSubscribeName(url), notifyListener) } notify := func(err error, duration time.Duration) { logger.Warnf("[Nacos Registry] subscribe failed, retry after %v: %v", duration, err) } _ = backoff.RetryNotify(operation, bo, notify) } ``` -- 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]
