From 978023ab1dcad48ef2a2297d6ec4c4e841c29a0c Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 29 Nov 2017 16:24:27 -0800 Subject: [PATCH] routing: ensure notifyTopologyChange is theadsafe --- routing/notifications.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/routing/notifications.go b/routing/notifications.go index dab7e5d2..cdb5f31c 100644 --- a/routing/notifications.go +++ b/routing/notifications.go @@ -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.