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

fix: experimental fix for runner connection failures #2116

Merged
merged 1 commit into from
Jul 22, 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
17 changes: 9 additions & 8 deletions backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ type Service struct {
pubSub *pubsub.Manager
controllerListListeners []ControllerListListener

// Map from endpoint to client.
// Map from runnerKey.String() to client.
clients *ttlcache.Cache[string, clients]

// Complete schema synchronised from the database.
Expand Down Expand Up @@ -962,7 +962,7 @@ func (s *Service) callWithRequest(
return nil, connect.NewError(connect.CodeNotFound, fmt.Errorf("no routes for module %q", module))
}
route := routes[rand.Intn(len(routes))] //nolint:gosec
client := s.clientsForEndpoint(route.Endpoint)
client := s.clientsForRunner(route.Runner, route.Endpoint)

callers, err := headers.GetCallers(req.Header())
if err != nil {
Expand Down Expand Up @@ -1133,17 +1133,17 @@ func (s *Service) getDeployment(ctx context.Context, key string) (*model.Deploym
return deployment, nil
}

// Return or create the RunnerService and VerbService clients for a Runner endpoint.
func (s *Service) clientsForEndpoint(endpoint string) clients {
clientItem := s.clients.Get(endpoint)
// Return or create the RunnerService and VerbService clients for a Runner.
func (s *Service) clientsForRunner(key model.RunnerKey, endpoint string) clients {
clientItem := s.clients.Get(key.String())
if clientItem != nil {
return clientItem.Value()
}
client := clients{
runner: rpc.Dial(ftlv1connect.NewRunnerServiceClient, endpoint, log.Error),
verb: rpc.Dial(ftlv1connect.NewVerbServiceClient, endpoint, log.Error),
}
s.clients.Set(endpoint, client, time.Minute)
s.clients.Set(key.String(), client, time.Minute)
return client
}

Expand Down Expand Up @@ -1436,7 +1436,7 @@ func (s *Service) terminateRandomRunner(ctx context.Context, key model.Deploymen
return false, nil
}
runner := runners[rand.Intn(len(runners))] //nolint:gosec
client := s.clientsForEndpoint(runner.Endpoint)
client := s.clientsForRunner(runner.Key, runner.Endpoint)
resp, err := client.runner.Terminate(ctx, connect.NewRequest(&ftlv1.TerminateRequest{DeploymentKey: key.String()}))
if err != nil {
return false, err
Expand Down Expand Up @@ -1476,7 +1476,8 @@ func (s *Service) reserveRunner(ctx context.Context, reconcile model.Deployment)
}

err = dal.WithReservation(reservationCtx, claim, func() error {
client = s.clientsForEndpoint(claim.Runner().Endpoint)
runner := claim.Runner()
client = s.clientsForRunner(runner.Key, runner.Endpoint)
_, err = client.runner.Reserve(reservationCtx, connect.NewRequest(&ftlv1.ReserveRequest{DeploymentKey: reconcile.Key.String()}))
if err != nil {
return fmt.Errorf("failed request to reserve a runner for %s at %s: %w", reconcile.Key, claim.Runner().Endpoint, err)
Expand Down
Loading