@@ -414,16 +414,25 @@ type scWrapper struct {
414414 balancer.SubConn
415415 // locality needs to be atomic because it can be updated while being read by
416416 // the picker.
417- locality atomic.Value // type clients.Locality
417+ locality atomic.Pointer [ clients.Locality ]
418418}
419419
420420func (scw * scWrapper ) updateLocalityID (lID clients.Locality ) {
421- scw .locality .Store (lID )
421+ // Store a pointer to a new, heap-allocated clients.Locality because the
422+ // pointer (scw.locality) is stored in an atomic.Pointer, and must remain
423+ // valid for concurrent access by other goroutines even after this function
424+ // returns.
425+ l := new (clients.Locality )
426+ * l = lID
427+ scw .locality .Store (l )
422428}
423429
424430func (scw * scWrapper ) localityID () clients.Locality {
425- lID , _ := scw .locality .Load ().(clients.Locality )
426- return lID
431+ lID := scw .locality .Load ()
432+ if lID == nil {
433+ return clients.Locality {}
434+ }
435+ return * lID
427436}
428437
429438func (b * clusterImplBalancer ) NewSubConn (addrs []resolver.Address , opts balancer.NewSubConnOptions ) (balancer.SubConn , error ) {
@@ -444,7 +453,7 @@ func (b *clusterImplBalancer) NewSubConn(addrs []resolver.Address, opts balancer
444453 // address's locality. https://github.com/grpc/grpc-go/issues/7339
445454 addr := connectedAddress (state )
446455 lID := xdsinternal .GetLocalityID (addr )
447- if xdsinternal . IsLocalityEmpty (lID ) {
456+ if (lID == clients. Locality {} ) {
448457 if b .logger .V (2 ) {
449458 b .logger .Infof ("Locality ID for %s unexpectedly empty" , addr )
450459 }
0 commit comments