Aias00 opened a new pull request, #3435: URL: https://github.com/apache/dubbo-go/pull/3435
## Problem `weightedRoundRobin` 的 `weight` 和 `current` 字段存在数据竞争:同一个字段混用了原子和非原子操作。 ### 具体问题 | 方法 | 字段 | 操作 | 问题 | |------|------|------|------| | `setWeight()` | `weight` | `robin.weight = weight` | 非原子写,与 `Weight()` 的 `atomic.LoadInt64` 竞争 | | `setWeight()` | `current` | `robin.current = 0` | 非原子写,与 `increaseCurrent()`/`Current()` 的 `atomic.AddInt64` 竞争 | | `increaseCurrent()` | `weight` | `robin.weight` | 非原子读,与 `setWeight()` 的写操作竞争 | ## Fix 将所有非原子访问替换为对应的原子操作: - `setWeight()`: `robin.weight = weight` → `atomic.StoreInt64(&robin.weight, weight)` - `setWeight()`: `robin.current = 0` → `atomic.StoreInt64(&robin.current, 0)` - `increaseCurrent()`: `robin.weight` → `atomic.LoadInt64(&robin.weight)` ## Verification `go test ./cluster/loadbalance/roundrobin/ -race -count=5` 通过,无数据竞争报告。 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
