From d97f954716993bfa3f5f7f50903b12e87c235fd7 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Fri, 8 Nov 2024 09:45:16 +1100 Subject: [PATCH] fix: add lock around client creation (#3350) --- backend/controller/controller.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/controller/controller.go b/backend/controller/controller.go index 33a271acd..1fc020bc5 100644 --- a/backend/controller/controller.go +++ b/backend/controller/controller.go @@ -248,6 +248,8 @@ type Service struct { increaseReplicaFailures map[string]int asyncCallsLock sync.Mutex runnerScaling scaling.RunnerScaling + + clientLock sync.Mutex } func New( @@ -1175,6 +1177,14 @@ func (s *Service) clientsForEndpoint(endpoint string) clients { if clientItem != nil { return clientItem.Value() } + s.clientLock.Lock() + defer s.clientLock.Unlock() + // Double check it was not added while we were waiting for the lock + clientItem = s.clients.Get(endpoint) + if clientItem != nil { + return clientItem.Value() + } + client := clients{ verb: rpc.Dial(ftlv1connect.NewVerbServiceClient, endpoint, log.Error), }