Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] - Create a new context with timeout per request #3163

Merged
merged 4 commits into from
Aug 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,11 +882,15 @@ func (e *Engine) verificationOverlapWorker(ctx context.Context) {
// DO NOT VERIFY at this stage of the pipeline.
matchedBytes := detector.Matches()
for _, match := range matchedBytes {
ctx, cancel := context.WithTimeout(ctx, time.Second*10)
results, err := detector.FromData(ctx, false, match)
ctx.Logger().Error(
err, "error finding results in chunk during verification overlap",
"detector", detector.Key.Type().String(),
)
cancel()
if err != nil {
ctx.Logger().Error(
err, "error finding results in chunk during verification overlap",
"detector", detector.Key.Type().String(),
)
}

if len(results) == 0 {
continue
Expand Down Expand Up @@ -980,9 +984,7 @@ func (e *Engine) detectChunk(ctx context.Context, data detectableChunk) {
if e.printAvgDetectorTime {
start = time.Now()
}
ctx, cancel := context.WithTimeout(ctx, time.Second*10)
defer common.Recover(ctx)
defer cancel()

isFalsePositive := detectors.GetFalsePositiveCheck(data.detector)

Expand All @@ -996,7 +998,10 @@ func (e *Engine) detectChunk(ctx context.Context, data detectableChunk) {
for _, matchBytes := range matches {
matchCount++
detectBytesPerMatch.Observe(float64(len(matchBytes)))

ctx, cancel := context.WithTimeout(ctx, time.Second*10)
results, err := data.detector.Detector.FromData(ctx, data.chunk.Verify, matchBytes)
cancel()
if err != nil {
ctx.Logger().Error(
err, "error finding results in chunk",
Expand Down
Loading