From 3915c6a56942bf60ac34d23aa5e9926fd0daa063 Mon Sep 17 00:00:00 2001 From: maurycy Date: Thu, 21 Jun 2018 08:43:37 +0200 Subject: [PATCH] routing: do not reacquire the lock for topology notifications --- routing/notifications.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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)