clustetresolver: Copy endpoints.Addresses slice from DNS updates to avoid data races (#7991)

This commit is contained in:
Arjan Singh Bal 2025-01-13 10:05:02 +05:30 committed by GitHub
parent f9bc335fc5
commit aad8a12b45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 0 deletions

View File

@ -144,6 +144,9 @@ func buildClusterImplConfigForDNS(g *nameGenerator, endpoints []resolver.Endpoin
pName := fmt.Sprintf("priority-%v", g.prefix) pName := fmt.Sprintf("priority-%v", g.prefix)
for i, e := range endpoints { for i, e := range endpoints {
retEndpoints[i] = hierarchy.SetInEndpoint(e, []string{pName}) 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{ return pName, &clusterimpl.LBConfig{
Cluster: mechanism.Cluster, Cluster: mechanism.Cluster,