Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vtgateproxy: add a lock for safety #467

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading