diff --git a/pkg/libstack/compose/composeplugin.go b/pkg/libstack/compose/composeplugin.go index acee07a90..c5de3325b 100644 --- a/pkg/libstack/compose/composeplugin.go +++ b/pkg/libstack/compose/composeplugin.go @@ -8,6 +8,7 @@ import ( "path/filepath" "slices" "strings" + "sync" "github.com/portainer/portainer/pkg/libstack" @@ -21,6 +22,8 @@ import ( "github.com/rs/zerolog/log" ) +var mu sync.Mutex + func withCli( ctx context.Context, options libstack.Options, @@ -47,9 +50,12 @@ func withCli( opts.ConfigDir = tempDir + mu.Lock() if err := cli.Initialize(opts); err != nil { + mu.Unlock() return fmt.Errorf("unable to initialize the Docker client: %w", err) } + mu.Unlock() defer cli.Client().Close() for _, r := range options.Registries { diff --git a/pkg/libstack/compose/status.go b/pkg/libstack/compose/status.go index ee8d2663f..afbd17728 100644 --- a/pkg/libstack/compose/status.go +++ b/pkg/libstack/compose/status.go @@ -130,7 +130,11 @@ func (c *ComposeDeployer) WaitForStatus(ctx context.Context, name string, status if err := withComposeService(ctx, nil, libstack.Options{ProjectName: name}, func(composeService api.Service, project *types.Project) error { var err error - containerSummaries, err = composeService.Ps(ctx, name, api.PsOptions{All: true}) + + psCtx, cancelFunc := context.WithTimeout(context.Background(), time.Minute) + defer cancelFunc() + containerSummaries, err = composeService.Ps(psCtx, name, api.PsOptions{All: true}) + return err }); err != nil {