Skip to content

Commit 7a81ab0

Browse files
authored
Add timeout for cloud-agent build (#727)
* add timeout for cloud-agent build * fix messaing for build timeout * increase build timeout to 15m
1 parent 1454db9 commit 7a81ab0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

cmd/lk/agent.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040

4141
const (
4242
maxSecretFileSize = 1024 * 1024 // 1MB
43+
buildTimeout = 15 * time.Minute
4344
)
4445

4546
var (
@@ -580,10 +581,15 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
580581
}
581582
}
582583

584+
buildContext, cancel := context.WithTimeout(ctx, buildTimeout)
585+
defer cancel()
583586
regions := []string{region}
584587
excludeFiles := []string{fmt.Sprintf("**/%s", config.LiveKitTOMLFile)}
585-
resp, err := agentsClient.CreateAgent(ctx, os.DirFS(workingDir), secrets, regions, excludeFiles, os.Stderr)
588+
resp, err := agentsClient.CreateAgent(buildContext, os.DirFS(workingDir), secrets, regions, excludeFiles, os.Stderr)
586589
if err != nil {
590+
if errors.Is(err, context.DeadlineExceeded) {
591+
return fmt.Errorf("build timed out possibly due to large image size")
592+
}
587593
if twerr, ok := err.(twirp.Error); ok {
588594
return fmt.Errorf("unable to create agent: %s", twerr.Msg())
589595
}
@@ -726,8 +732,10 @@ func deployAgent(ctx context.Context, cmd *cli.Command) error {
726732
}
727733
}
728734

735+
buildContext, cancel := context.WithTimeout(ctx, buildTimeout)
736+
defer cancel()
729737
excludeFiles := []string{fmt.Sprintf("**/%s", config.LiveKitTOMLFile)}
730-
if err := agentsClient.DeployAgent(ctx, agentId, os.DirFS(workingDir), secrets, excludeFiles, os.Stderr); err != nil {
738+
if err := agentsClient.DeployAgent(buildContext, agentId, os.DirFS(workingDir), secrets, excludeFiles, os.Stderr); err != nil {
731739
if twerr, ok := err.(twirp.Error); ok {
732740
return fmt.Errorf("unable to deploy agent: %s", twerr.Msg())
733741
}

0 commit comments

Comments
 (0)