mochengqian commented on PR #915:
URL: https://github.com/apache/dubbo-go-pixiu/pull/915#issuecomment-4322304262

   > ### 代码审查
   > 发现 1 个问题:
   > 
   > 1. **数据竞争:非原子读/写`PrePickEndpointIndex`操作`carryOverRuntimeStateFrom`**
   >    `round_robin.go``PrePickEndpointIndex`(第 41 行)仅通过` __init__` 
访问`atomic.AddUint32`,但新`carryOverRuntimeStateFrom`函数使用普通赋值复制了该字段。Go 
的内存模型将对同一变量混合使用原子访问和非原子访问视为数据竞争——`go test -race`会对此发出警告。
   >    解决方法:使用`atomic.LoadUint32`/ `atomic.StoreUint32`:
   >    ```go
   >    atomic.StoreUint32(&clusterConfig.PrePickEndpointIndex, 
atomic.LoadUint32(&oldConfig.PrePickEndpointIndex))
   >    ```
   >    
   >    
   >        
   >          
   >        
   >    
   >          
   >        
   >    
   >        
   >      
   >    
https://github.com/apache/dubbo-go-pixiu/blob/7350a07c26f2bc14abb869e7cd4dee4eb7536bcb/pkg/server/cluster_manager.go#L407-L412
   >    
   >    
(原子写入路径供参考:)https://github.com/apache/dubbo-go-pixiu/blob/7350a07c26f2bc14abb869e7cd4dee4eb7536bcb/pkg/cluster/loadbalancer/roundrobin/round_robin.go#L39-L43
   >    )
   > 
   > 🤖 由[Claude Code生成](https://claude.ai/code)
   > 
   > - 如果这篇代码审查对您有帮助,请点赞👍。否则,请点踩👎。
   
   good catch!我确实没从并发内存模型层面考虑,现已修复问题.


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