Skip to content

Commit

Permalink
fix: add lock around client creation (#3350)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored Nov 7, 2024
1 parent c8a2244 commit d97f954
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ type Service struct {
increaseReplicaFailures map[string]int
asyncCallsLock sync.Mutex
runnerScaling scaling.RunnerScaling

clientLock sync.Mutex
}

func New(
Expand Down Expand Up @@ -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),
}
Expand Down

0 comments on commit d97f954

Please sign in to comment.