diff --git a/environment/environment.go b/environment/environment.go index 47078e76..7a8b91c9 100644 --- a/environment/environment.go +++ b/environment/environment.go @@ -257,10 +257,12 @@ func (env *Environment) RunBackground(ctx context.Context, explanation, command, } // Start the service + startCtx, cancel := context.WithTimeout(ctx, serviceStartTimeout) + defer cancel() svc, err := serviceState.AsService(dagger.ContainerAsServiceOpts{ Args: args, UseEntrypoint: useEntrypoint, - }).Start(ctx) + }).Start(startCtx) if err != nil { var exitErr *dagger.ExecError if errors.As(err, &exitErr) { diff --git a/environment/service.go b/environment/service.go index b148900e..f05e682c 100644 --- a/environment/service.go +++ b/environment/service.go @@ -4,10 +4,15 @@ import ( "context" "errors" "fmt" + "time" "dagger.io/dagger" ) +var ( + serviceStartTimeout = 30 * time.Second +) + type Service struct { Config *ServiceConfig `json:"config"` Endpoints EndpointMappings `json:"endpoints"` @@ -59,10 +64,12 @@ func (env *Environment) startService(ctx context.Context, cfg *ServiceConfig) (* } // Start the service + startCtx, cancel := context.WithTimeout(ctx, serviceStartTimeout) + defer cancel() svc, err := container.AsService(dagger.ContainerAsServiceOpts{ Args: args, UseEntrypoint: true, - }).Start(ctx) + }).Start(startCtx) if err != nil { var exitErr *dagger.ExecError if errors.As(err, &exitErr) {