Skip to content

Commit 62b9185

Browse files
authored
clustetresolver: Copy endpoints.Addresses slice from DNS updates to avoid data races (#7991) (#8004)
1 parent 724f450 commit 62b9185

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

xds/internal/balancer/clusterresolver/configbuilder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ func buildClusterImplConfigForDNS(g *nameGenerator, endpoints []resolver.Endpoin
144144
pName := fmt.Sprintf("priority-%v", g.prefix)
145145
for i, e := range endpoints {
146146
retEndpoints[i] = hierarchy.SetInEndpoint(e, []string{pName})
147+
// Copy the nested address field as slice fields are shared by the
148+
// iteration variable and the original slice.
149+
retEndpoints[i].Addresses = append([]resolver.Address{}, e.Addresses...)
147150
}
148151
return pName, &clusterimpl.LBConfig{
149152
Cluster: mechanism.Cluster,

0 commit comments

Comments
 (0)