0x-infinity opened a new issue, #993:
URL: https://github.com/apache/incubator-seata-go/issues/993

   ### 讨论详情
   
   ### Description
   In `pkg/remoting/loadbalance/consistent_hash_loadbalance.go`, the 
`refreshHashCircle()` method updates shared data without holding a lock, while 
the `pick()` method concurrently reads this data.
   
   **Problem Code**: 
`pkg/remoting/loadbalance/consistent_hash_loadbalance.go:88-113`
   ```go
   func (c *Consistent) refreshHashCircle(sessions *sync.Map) {
       var sortedHashNodes []int64
       hashCircle := make(map[int64]getty.Session)
       // ... build data
   
       // Direct assignment without locking, races with reads in pick()
       c.sortedHashNodes = sortedHashNodes
       c.hashCircle = hashCircle
   }
   
   func (c *Consistent) pick(sessions *sync.Map, key string) getty.Session {
       // Reading c.sortedHashNodes without complete lock protection
       index := sort.Search(len(c.sortedHashNodes), func(i int) bool {
           return c.sortedHashNodes[i] >= hashKey
       })
       // ...
       if session.IsClosed() {
           go c.refreshHashCircle(sessions)  // async refresh, has race 
condition
           return c.firstKey()
       }
   }
   ```
   
   ### Why Need Improve
   1. Clear data race exists, potentially causing unpredictable behavior
   2. May cause panic (slice bounds out of range) in high-concurrency scenarios
   3. May read partially updated data, leading to inaccurate load 
balancingRetry[Claude can make mistakes. Please double-check 
responses.](https://support.anthropic.com/en/articles/8525154-claude-is-providing-incorrect-or-misleading-responses-what-s-going-on)
   
   ### 📚 相关背景
   
   _No response_


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