diff --git a/go/vt/vtgateproxy/discovery.go b/go/vt/vtgateproxy/discovery.go index 7a5df534e96..8bef891b485 100644 --- a/go/vt/vtgateproxy/discovery.go +++ b/go/vt/vtgateproxy/discovery.go @@ -66,6 +66,7 @@ type JSONGateResolver struct { clientConn resolver.ClientConn poolType string currentAddrs []resolver.Address + mu sync.Mutex } func (r *JSONGateResolver) ResolveNow(o resolver.ResolveNowOptions) {} @@ -398,6 +399,11 @@ func (b *JSONGateResolverBuilder) update(r *JSONGateResolver) error { targets := b.getTargets(r.poolType) + // There should only ever be a single goroutine calling update on a given Resolver, + // but add a lock just in case to ensure that the r.currentAddrs are in fact synchronized + r.mu.Lock() + defer r.mu.Unlock() + var addrs []resolver.Address for _, target := range targets { addrs = append(addrs, resolver.Address{Addr: target.Addr, Attributes: attributes.New(PoolTypeAttr, r.poolType)})