routing: ensure notifyTopologyChange is theadsafe

This commit is contained in:
Olaoluwa Osuntokun 2017-11-29 16:24:27 -08:00
parent 33ce4e5689
commit 978023ab1d
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -110,15 +110,19 @@ type topologyClient struct {
// notifyTopologyChange notifies all registered clients of a new change in
// graph topology in a non-blocking.
func (r *ChannelRouter) notifyTopologyChange(topologyDiff *TopologyChange) {
if len(r.topologyClients) != 0 {
r.RLock()
numClients := len(r.topologyClients)
r.RUnlock()
if numClients != 0 {
log.Tracef("Sending topology notification to %v clients %v",
len(r.topologyClients),
numClients,
newLogClosure(func() string {
return spew.Sdump(topologyDiff)
}),
)
}
r.RLock()
for _, client := range r.topologyClients {
client.wg.Add(1)
@ -142,6 +146,7 @@ func (r *ChannelRouter) notifyTopologyChange(topologyDiff *TopologyChange) {
}
}(client)
}
r.RUnlock()
}
// TopologyChange represents a new set of modifications to the channel graph.