Skip to content

Commit

Permalink
add a lock for safety (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
demmer authored Jul 24, 2024
1 parent 6ee8654 commit 24447d0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions go/vt/vtgateproxy/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down Expand Up @@ -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)})
Expand Down

0 comments on commit 24447d0

Please sign in to comment.