From 62b9185a6296155e47efd39d60298d8de0a6ed1d Mon Sep 17 00:00:00 2001 From: Arjan Singh Bal <46515553+arjan-bal@users.noreply.github.com> Date: Mon, 13 Jan 2025 11:38:55 +0530 Subject: [PATCH] clustetresolver: Copy endpoints.Addresses slice from DNS updates to avoid data races (#7991) (#8004) --- xds/internal/balancer/clusterresolver/configbuilder.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xds/internal/balancer/clusterresolver/configbuilder.go b/xds/internal/balancer/clusterresolver/configbuilder.go index 683f973b3fbf..9a3a71c2e5cc 100644 --- a/xds/internal/balancer/clusterresolver/configbuilder.go +++ b/xds/internal/balancer/clusterresolver/configbuilder.go @@ -144,6 +144,9 @@ func buildClusterImplConfigForDNS(g *nameGenerator, endpoints []resolver.Endpoin pName := fmt.Sprintf("priority-%v", g.prefix) for i, e := range endpoints { retEndpoints[i] = hierarchy.SetInEndpoint(e, []string{pName}) + // Copy the nested address field as slice fields are shared by the + // iteration variable and the original slice. + retEndpoints[i].Addresses = append([]resolver.Address{}, e.Addresses...) } return pName, &clusterimpl.LBConfig{ Cluster: mechanism.Cluster,