From 81cffebc9ba139208deba55a4c934e4d9b8293c4 Mon Sep 17 00:00:00 2001 From: Henry Robinson Date: Tue, 23 Jul 2024 15:56:43 +0100 Subject: [PATCH] Access JSONGateResolverBuilder.resolvers under a lock (#463) Signed-off-by: Henry Robinson --- go/vt/vtgateproxy/discovery.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/go/vt/vtgateproxy/discovery.go b/go/vt/vtgateproxy/discovery.go index a396237bad3..7a019e49030 100644 --- a/go/vt/vtgateproxy/discovery.go +++ b/go/vt/vtgateproxy/discovery.go @@ -210,6 +210,7 @@ func (b *JSONGateResolverBuilder) start() error { } parseCount.Add("changed", 1) + b.mu.RLock() // notify all the resolvers that the targets changed for _, r := range b.resolvers { err = b.update(r) @@ -217,6 +218,7 @@ func (b *JSONGateResolverBuilder) start() error { log.Errorf("Failed to update resolver: %v", err) } } + b.mu.RUnlock() } }() @@ -422,7 +424,10 @@ func (b *JSONGateResolverBuilder) Build(target resolver.Target, cc resolver.Clie if err != nil { return nil, err } + + b.mu.Lock() b.resolvers = append(b.resolvers, r) + b.mu.Unlock() return r, nil }