Skip to content

Commit ee8e198

Browse files
committed
fix race
1 parent 7720fe3 commit ee8e198

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

internal/xds/balancer/clusterresolver/clusterresolver.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,11 @@ func (b *clusterResolverBalancer) updateChildConfig() {
248248
b.logger.Infof("Built child policy config: %s", pretty.ToJSON(childCfg))
249249
}
250250

251+
newEndpoints := make([]resolver.Endpoint, len(endpoints))
251252
flattenedAddrs := make([]resolver.Address, len(endpoints))
252-
for i := range endpoints {
253+
for i, e := range endpoints {
254+
newEP := e
255+
newEP.Addresses = make([]resolver.Address, len(e.Addresses))
253256
for j := range endpoints[i].Addresses {
254257
addr := endpoints[i].Addresses[j]
255258
addr.BalancerAttributes = endpoints[i].Attributes
@@ -268,12 +271,13 @@ func (b *clusterResolverBalancer) updateChildConfig() {
268271
// address used by the transport. This workaround can be removed once
269272
// the old pickfirst is removed.
270273
// See https://github.com/grpc/grpc-go/issues/7339
271-
endpoints[i].Addresses[j] = addr
274+
newEP.Addresses[j] = addr
272275
}
276+
newEndpoints[i] = newEP
273277
}
274278
if err := b.child.UpdateClientConnState(balancer.ClientConnState{
275279
ResolverState: resolver.State{
276-
Endpoints: endpoints,
280+
Endpoints: newEndpoints,
277281
Addresses: flattenedAddrs,
278282
ServiceConfig: b.configRaw,
279283
Attributes: b.attrsWithClient,

internal/xds/xdsclient/tests/loadreport_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ func (s) TestConcurrentReportLoad(t *testing.T) {
491491
// TestConcurrentChannels verifies that we can create multiple gRPC channels
492492
// concurrently with a shared XDSClient, each of which will create a new LRS
493493
// stream without any race.
494-
func (s) TestConcurrentChannels(t *testing.T) {
494+
func TestConcurrentChannels(t *testing.T) {
495495
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
496496
defer cancel()
497497

0 commit comments

Comments
 (0)