Skip to content

Commit

Permalink
fix: check ctx for cancellation in UploadAndAnalyzeWithIgnores (#741)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch authored Dec 19, 2024
1 parent dcbf840 commit e449b26
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions infrastructure/code/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,13 @@ func (sc *Scanner) UploadAndAnalyze(ctx context.Context, files <-chan string, pa
}

func (sc *Scanner) UploadAndAnalyzeWithIgnores(ctx context.Context, path string, files <-chan string, changedFiles map[string]bool, t *progress.Tracker) (issues []snyk.Issue, err error) {
logger := config.CurrentConfig().Logger().With().Str("method", "code.UploadAndAnalyzeWithIgnores").Logger()
if ctx.Err() != nil {
progress.Cancel(t.GetToken())
sc.c.Logger().Info().Msg("Canceling Code scanner received cancellation signal")
return issues, nil
}

logger := sc.c.Logger().With().Str("method", "code.UploadAndAnalyzeWithIgnores").Logger()
span := sc.BundleUploader.instrumentor.StartSpan(ctx, "code.uploadAndAnalyze")
defer sc.BundleUploader.instrumentor.Finish(span)

Expand All @@ -440,7 +446,7 @@ func (sc *Scanner) UploadAndAnalyzeWithIgnores(ctx context.Context, path string,
}

sarif, bundleHash, err := sc.codeScanner.UploadAndAnalyze(ctx, requestId, target, files, changedFiles)
if err != nil {
if err != nil || ctx.Err() != nil {
return []snyk.Issue{}, err
}
sc.bundleHashesMutex.Lock()
Expand Down

0 comments on commit e449b26

Please sign in to comment.