diff --git a/plugins/runner/internal/runtimehandler/binary/handler.go b/plugins/runner/internal/runtimehandler/binary/handler.go index 5930eb42d..f5eca6741 100644 --- a/plugins/runner/internal/runtimehandler/binary/handler.go +++ b/plugins/runner/internal/runtimehandler/binary/handler.go @@ -52,10 +52,10 @@ type binaryRuntimeHandler struct { inputDirMountPoint string imageCleanup func() ready bool - - mu sync.Mutex } +var mu sync.Mutex + func New(ctx context.Context, config types.PluginConfig) (runtimehandler.PluginRuntimeHandler, error) { return &binaryRuntimeHandler{ config: config, @@ -65,8 +65,8 @@ func New(ctx context.Context, config types.PluginConfig) (runtimehandler.PluginR //nolint:cyclop func (h *binaryRuntimeHandler) Start(ctx context.Context) error { - h.mu.Lock() - defer h.mu.Unlock() + mu.Lock() + defer mu.Unlock() image, cleanup, err := containerrootfs.GetImageWithCleanup(ctx, h.config.ImageName) if err != nil { diff --git a/plugins/runner/internal/runtimehandler/docker/handler.go b/plugins/runner/internal/runtimehandler/docker/handler.go index ed0d99d6b..1971b3791 100644 --- a/plugins/runner/internal/runtimehandler/docker/handler.go +++ b/plugins/runner/internal/runtimehandler/docker/handler.go @@ -26,6 +26,7 @@ import ( "net" "os" "path/filepath" + "sync" "sync/atomic" "time" @@ -62,6 +63,8 @@ type containerRuntimeHandler struct { runningErr atomic.Pointer[error] } +var mu sync.Mutex + func New(ctx context.Context, config types.PluginConfig) (runtimehandler.PluginRuntimeHandler, error) { // Load docker client client, err := newDockerClient() @@ -76,6 +79,9 @@ func New(ctx context.Context, config types.PluginConfig) (runtimehandler.PluginR } func (h *containerRuntimeHandler) Start(ctx context.Context) error { + mu.Lock() + defer mu.Unlock() + // Pull scanner image if required err := h.pullPluginImage(ctx) if err != nil { diff --git a/scanner/families/plugins/runner/runner.go b/scanner/families/plugins/runner/runner.go index 4b8f8449b..b85c7d384 100644 --- a/scanner/families/plugins/runner/runner.go +++ b/scanner/families/plugins/runner/runner.go @@ -22,7 +22,6 @@ import ( "errors" "fmt" "io" - "sync" apitypes "github.com/openclarity/vmclarity/api/types" "github.com/openclarity/vmclarity/core/log" @@ -39,8 +38,6 @@ import ( type Scanner struct { name string config config.Config - - mu sync.Mutex } func New(_ context.Context, name string, config types.ScannersConfig) (families.Scanner[*types.ScannerResult], error) { @@ -104,13 +101,11 @@ func (s *Scanner) Scan(ctx context.Context, inputType common.InputType, userInpu Err: nil, } - s.mu.Lock() if err := rr.Start(ctx); err != nil { res.Err = fmt.Errorf("failed to start plugin runner: %w", err) resChan <- res return } - s.mu.Unlock() if err := rr.WaitReady(ctx); err != nil { res.Err = fmt.Errorf("failed to wait for plugin scanner to be ready: %w", err)