mochengqian opened a new issue, #3304:
URL: https://github.com/apache/dubbo-go/issues/3304

   ### ✅ 验证清单
   
   - [x] 🔍 我已经搜索过 [现有 
Issues](https://github.com/apache/dubbo-go/issues),确信这不是重复问题
   
   ### 🚀 Go 版本
   
   go1.26.1 darwin/arm64
   
   ### 📦 Dubbo-go 版本
   
   dubbo.apache.org/dubbo-go/[email protected]
   
   ### 🖥️ 服务端配置
   
   Dubbo-go v3.3.2-20260419  本地 Triple provider: - address: 127.0.0.1:20450 - 
service: greet.GreetService - 用于 retry / high concurrency / race detector 验证
   
   ### 💻 客户端配置
   
   Dubbo-go v3.3.2-20260419  本地 high-concurrency client test: - 多个 goroutine 
并发创建 Triple client - 通过生成代码调用 retry/proto.NewGreetService() - 使用 explicit URL: 
tri://127.0.0.1:20450 - 运行 go test -race
   
   ### 🌐 协议配置
   
   Triple
   
   ### 📋 注册中心配置
   
   无注册中心。  测试使用 explicit Triple URL: tri://127.0.0.1:20450
   
   ### 💾 操作系统
   
   🍎 macOS
   
   ### 📝 Bug 描述
   
   在使用 `dubbo.apache.org/dubbo-go/[email protected]` 对 retry / Triple 路径做高并发和 
`go test -race` 验证时,race detector 报告 data race。
   
   普通 retry failure matrix 可以通过,但在多个 goroutine 并发创建 Triple client / service 
或并发调用 Triple protocol 初始化路径时,会触发共享状态竞争。
   
   影响范围:
   - Triple protocol 初始化
   - 并发创建 client / service
   - BaseProtocol invoker list 更新
   - 高并发测试和真实业务中动态创建客户端的场景
   
   ### 🔄 重现步骤
   
   1. 启动一个本地 Triple provider,例如:
      - address: `127.0.0.1:20450`
      - service: `greet.GreetService`
   
   2. 编写一个 high-concurrency Go test:
      - 启动多个 goroutine;
      - 每个 goroutine 创建 Triple client;
      - 通过 generated client 调用 `retry/proto.NewGreetService()`;
      - explicit URL 使用 `tri://127.0.0.1:20450`。
   
   3. 使用 race detector 运行测试:
   
   ```bash
   go test -race
   ```
   
   4. 观察 race detector 输出。
   
   ### ✅ 预期行为
   
   1. Triple protocol 初始化应是并发安全的。
   2. 多个 goroutine 并发创建 client / service 时不应出现 data race。
   3. `BaseProtocol` 内部 invoker list 的 Set/Get 操作应避免并发读写竞争。
   4. `go test -race` 不应报告读写竞争。
   5. retry / timeout / failure matrix 在高并发下应保持语义稳定,且不出现 nil panic 或非预期最终错误。
   
   ### ❌ 实际行为
   
   `go test -race` 报告 data race。
   
   第一类竞争发生在 Triple protocol 单例初始化:
   
   ```text
   WARNING: DATA RACE
   Read at ... by goroutine 48:
     dubbo.apache.org/dubbo-go/v3/protocol/triple.GetProtocol()
         .../dubbo-go/[email protected]/protocol/triple/triple.go:208
   
   Previous write at ... by goroutine 60:
     dubbo.apache.org/dubbo-go/v3/protocol/triple.GetProtocol()
         .../dubbo-go/[email protected]/protocol/triple/triple.go:209
   ```
   
   第二类竞争发生在 `BaseProtocol.SetInvokers()`:
   
   ```text
   WARNING: DATA RACE
   Read at ... by goroutine 54:
     dubbo.apache.org/dubbo-go/v3/protocol/base.(*BaseProtocol).SetInvokers()
         .../dubbo-go/[email protected]/protocol/base/base_protocol.go:70
     dubbo.apache.org/dubbo-go/v3/protocol/triple.(*TripleProtocol).Refer()
         .../dubbo-go/[email protected]/protocol/triple/triple.go:162
   
   Previous write at ... by goroutine 60:
     dubbo.apache.org/dubbo-go/v3/protocol/triple.NewTripleProtocol()
         .../dubbo-go/[email protected]/protocol/triple/triple.go:202
     dubbo.apache.org/dubbo-go/v3/protocol/triple.GetProtocol()
         .../dubbo-go/[email protected]/protocol/triple/triple.go:209
   ```
   
   测试最终报告:
   
   ```text
   race detected during execution of test
   ```
   
   普通 retry failure matrix 本身可以通过,因此这不是 retry 业务语义失败,而是 Triple / BaseProtocol 
的并发安全问题。
   
   
   ### 💡 可能的解决方案
   
   建议检查 Triple protocol 和 BaseProtocol 的共享状态访问:
   
   1. Triple protocol singleton 初始化需要并发安全保护,例如:
      - `sync.Once`
      - mutex
      - 或其他明确的 lazy init 同步机制
   
   2. `BaseProtocol` 内部 invoker list / map 的 Set/Get 需要并发安全保护,例如:
      - mutex
      - `sync.Map`
      - copy-on-write
      - 初始化阶段与运行阶段状态隔离
   
   3. 增加 race detector 测试覆盖:
      - 并发创建 Triple client
      - 并发创建 Triple service
      - provider 中途退出 / 重启
      - 高并发 retry
   
   4. 修复时需要注意兼容性,不应改变:
      - method lookup 行为
      - timeout / retry / error propagation 语义
      - Triple 协议调用语义
   


-- 
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