From 652b1067f5ebdc30ec1df883fc08a847653a21cb Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 1 Feb 2019 09:05:03 +0000 Subject: [PATCH] fix data race --- registry/gossip/util.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/registry/gossip/util.go b/registry/gossip/util.go index 5d0160a7..5e44e375 100644 --- a/registry/gossip/util.go +++ b/registry/gossip/util.go @@ -70,21 +70,30 @@ func addNodes(old, neu []*registry.Node) []*registry.Node { } func addServices(old, neu []*registry.Service) []*registry.Service { + var srv []*registry.Service + for _, s := range neu { var seen bool - for i, o := range old { + for _, o := range old { if o.Version == s.Version { - s.Nodes = addNodes(o.Nodes, s.Nodes) + var sp *registry.Service + // make copy + *sp = *o + // set nodes + sp.Nodes = addNodes(o.Nodes, s.Nodes) + + // mark as seen seen = true - old[i] = s + srv = append(srv, sp) break } } if !seen { - old = append(old, s) + srv = append(srv, cp([]*registry.Service{s})...) } } - return old + + return srv } func delNodes(old, del []*registry.Node) []*registry.Node {