Skip to content

Commit aad8a12

Browse files
authored
clustetresolver: Copy endpoints.Addresses slice from DNS updates to avoid data races (#7991)
1 parent f9bc335 commit aad8a12

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

xds/internal/balancer/clusterresolver/configbuilder.go

+3
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)