diff --git a/routing/notifications.go b/routing/notifications.go index c263fc2e..f4bbaec0 100644 --- a/routing/notifications.go +++ b/routing/notifications.go @@ -113,15 +113,19 @@ func (r *ChannelRouter) notifyTopologyChange(topologyDiff *TopologyChange) { r.RLock() numClients := len(r.topologyClients) r.RUnlock() - if numClients != 0 { - log.Tracef("Sending topology notification to %v clients %v", - numClients, - newLogClosure(func() string { - return spew.Sdump(topologyDiff) - }), - ) + + // Do not reacquire the lock twice unnecessarily. + if numClients == 0 { + return } + log.Tracef("Sending topology notification to %v clients %v", + numClients, + newLogClosure(func() string { + return spew.Sdump(topologyDiff) + }), + ) + r.RLock() for _, client := range r.topologyClients { client.wg.Add(1)