Merge pull request #3884 from bhandras/hotfix

routing: clean up locking on topology change
This commit is contained in:
Olaoluwa Osuntokun 2020-01-06 18:00:38 -08:00 committed by GitHub
commit 08ebefa8a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -118,10 +118,9 @@ type topologyClient struct {
// graph topology in a non-blocking. // graph topology in a non-blocking.
func (r *ChannelRouter) notifyTopologyChange(topologyDiff *TopologyChange) { func (r *ChannelRouter) notifyTopologyChange(topologyDiff *TopologyChange) {
r.RLock() r.RLock()
numClients := len(r.topologyClients) defer r.RUnlock()
r.RUnlock()
// Do not reacquire the lock twice unnecessarily. numClients := len(r.topologyClients)
if numClients == 0 { if numClients == 0 {
return return
} }
@ -133,7 +132,6 @@ func (r *ChannelRouter) notifyTopologyChange(topologyDiff *TopologyChange) {
}), }),
) )
r.RLock()
for _, client := range r.topologyClients { for _, client := range r.topologyClients {
client.wg.Add(1) client.wg.Add(1)
@ -157,7 +155,6 @@ func (r *ChannelRouter) notifyTopologyChange(topologyDiff *TopologyChange) {
} }
}(client) }(client)
} }
r.RUnlock()
} }
// TopologyChange represents a new set of modifications to the channel graph. // TopologyChange represents a new set of modifications to the channel graph.