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

   ### Code review
   
   Found 1 issue:
   
   1. **Data race: non-atomic read/write of `PrePickEndpointIndex` in 
`carryOverRuntimeStateFrom`**
   
      `round_robin.go` accesses `PrePickEndpointIndex` exclusively via 
`atomic.AddUint32` (line 41), but the new `carryOverRuntimeStateFrom` function 
copies the field with a plain assignment. Go's memory model treats mixing 
atomic and non-atomic accesses to the same variable as a data race — `go test 
-race` will flag this.
   
      Fix: use `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
   
      (The atomic write path for reference: 
https://github.com/apache/dubbo-go-pixiu/blob/7350a07c26f2bc14abb869e7cd4dee4eb7536bcb/pkg/cluster/loadbalancer/roundrobin/round_robin.go#L39-L43)
   
   🤖 Generated with [Claude Code](https://claude.ai/code)
   
   <sub>- If this code review was useful, please react with 👍. Otherwise, react 
with 👎.</sub>


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