Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,20 @@ func (d *dataProxyDiscoverer) lookup() {
d.log.Infof("update server endpoint list %s: %v", d.url, allEndpointAddrStr)
}

d.RLock()
defer d.RUnlock()
if len(addEndpoints) > 0 || len(delEndpoints) > 0 {
// Copy the handler list while holding the lock, then invoke callbacks after
// releasing it, to avoid calling external code while holding the lock: if a
// handler calls back into AddEventHandler/DelEventHandler/GetEndpoints
// (which need Lock/RLock) from within OnEndpointUpdate, the same goroutine
// re-entering the RWMutex would deadlock
d.RLock()
handlers := make([]discoverer.EventHandler, 0, len(d.eventHandlers))
for h := range d.eventHandlers {
handlers = append(handlers, h)
}
d.RUnlock()

for _, h := range handlers {
h.OnEndpointUpdate(allEndpoints, addEndpoints, delEndpoints)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,20 @@ func (d *dnsDiscoverer) lookup() {
d.log.Infof("update domain host list %s: %v", d.domain, allHostStr)
}

d.RLock()
defer d.RUnlock()
if len(addEndpoints) > 0 || len(delEndpoints) > 0 {
// Copy the handler list while holding the lock, then invoke callbacks after
// releasing it, to avoid calling external code while holding the lock: if a
// handler calls back into AddEventHandler/DelEventHandler/GetEndpoints
// (which need Lock/RLock) from within OnEndpointUpdate, the same goroutine
// re-entering the RWMutex would deadlock
d.RLock()
handlers := make([]EventHandler, 0, len(d.eventHandlers))
for h := range d.eventHandlers {
handlers = append(handlers, h)
}
d.RUnlock()

for _, h := range handlers {
h.OnEndpointUpdate(allEndpoints, addEndpoints, delEndpoints)
}
}
Expand Down
Loading