Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
fix(plugin): fix plugin family runner race condition (#1824)
Browse files Browse the repository at this point in the history
* fix(plugin): fix race condition

* style(plugin): rename cleanup to finishRunner
  • Loading branch information
zsoltkacsandi authored Jun 21, 2024
1 parent 0750034 commit 90f87ca
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions scanner/families/plugins/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ func (s *Scanner) Run(ctx context.Context, sourceType utils.SourceType, userInpu
s.sendResults(retResults, fmt.Errorf("failed to create plugin runner: %w", err))
return
}
defer func() {

finishRunner := func(ctx context.Context) {
if err := rr.Stop(ctx); err != nil {
s.logger.WithError(err).Errorf("failed to stop runner")
}
Expand All @@ -88,21 +89,24 @@ func (s *Scanner) Run(ctx context.Context, sourceType utils.SourceType, userInpu
if err := rr.Remove(ctx); err != nil {
s.logger.WithError(err).Errorf("failed to remove runner")
}
}() //nolint:errcheck
} //nolint:errcheck

if err := rr.Start(ctx); err != nil {
finishRunner(ctx)
s.sendResults(retResults, fmt.Errorf("failed to start plugin runner: %w", err))
return
}

if err := rr.WaitReady(ctx); err != nil {
finishRunner(ctx)
s.sendResults(retResults, fmt.Errorf("failed to wait for plugin scanner to be ready: %w", err))
return
}

// Get plugin metadata
metadata, err := rr.Metadata(ctx)
if err != nil {
finishRunner(ctx)
s.sendResults(retResults, fmt.Errorf("failed to get plugin scanner metadata: %w", err))
return
}
Expand All @@ -128,21 +132,26 @@ func (s *Scanner) Run(ctx context.Context, sourceType utils.SourceType, userInpu
}()

if err := rr.Run(ctx); err != nil {
finishRunner(ctx)
s.sendResults(retResults, fmt.Errorf("failed to run plugin scanner: %w", err))
return
}

if err := rr.WaitDone(ctx); err != nil {
finishRunner(ctx)
s.sendResults(retResults, fmt.Errorf("failed to wait for plugin scanner to finish: %w", err))
return
}

findings, pluginResult, err := s.parseResults(ctx, rr)
if err != nil {
finishRunner(ctx)
s.sendResults(retResults, fmt.Errorf("failed to parse plugin scanner results: %w", err))
return
}

finishRunner(ctx)

retResults.Findings = findings
retResults.Output = pluginResult
s.sendResults(retResults, nil)
Expand Down

0 comments on commit 90f87ca

Please sign in to comment.