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

   ### Problem
   
   `registry/etcdv3.dataListener.interestedURL` is a plain `[]*common.URL` 
slice with no lock:
   
   ```go
   // registry/etcdv3/listener.go
   type dataListener struct {
       interestedURL []*common.URL
       listener      config_center.ConfigurationListener
   }
   
   func (l *dataListener) AddInterestedURL(url *common.URL) {
       l.interestedURL = append(l.interestedURL, url)   // DoSubscribe path
   }
   
   func (l *dataListener) DataChange(eventType remoting.Event) bool {
       ...
       if slices.ContainsFunc(l.interestedURL, serviceURL.URLEqual) {   // etcd 
watch goroutine
           l.listener.Process(...)
       }
   }
   ```
   
   `AddInterestedURL` is called from `DoSubscribe` (consumer subscribe path) 
while `DataChange` runs on the etcd watch goroutine (`ListenServiceEvent`). 
Concurrent `append` (which may reallocate the slice header) and 
`slices.ContainsFunc` (which reads the slice header/elements) is a data race. 
`go test -race` flags it.
   
   ### Current behavior
   
   Two near-simultaneous `DoSubscribe` calls, or a subscribe concurrent with an 
incoming etcd watch event, race on the `interestedURL` slice header → torn 
reads, missed event matching, or stale reads dropping events.
   
   ### Expected behavior
   
   `interestedURL` reads and writes must be guarded; `DataChange` must not hold 
the lock across the external `Process` callback.
   
   ### Suggested approach
   
   - Add a `sync.RWMutex` to `dataListener`.
   - `AddInterestedURL` takes the write lock.
   - `DataChange` does the `slices.ContainsFunc` check under `RLock`, releases 
it, then dispatches `Process` outside the lock.
   
   ### Acceptance criteria
   
   - [ ] `interestedURL` is accessed under the mutex in both `AddInterestedURL` 
and `DataChange`.
   - [ ] `DataChange` dispatches `Process` outside the lock.
   - [ ] A concurrency test (concurrent `AddInterestedURL` vs `DataChange`) 
passes under `-race`.
   


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