Skip to content

resolve race condition in result deduplication cache - #5359

Merged
kvnphvm merged 1 commit into
mainfrom
int-1085-resolve-race-condition-in-result-deduplication-cache
Sep 30, 2026
Merged

kvnphvm merged 1 commit into
mainfrom
int-1085-resolve-race-condition-in-result-deduplication-cache

Conversation

@kvnphvm

@kvnphvm kvnphvm commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Description:

Between checking if a result is in the deduplication cache and adding it, another goroutine could add it, or it could be evicted. This contributes to varying result counts.

Change to ContainsOrAdd so that it is one atomic step

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

Note

Medium Risk
Changes concurrent deduplication on the shared notifier dispatch path, which directly affects reported finding counts; scope is narrow and covered by new concurrency tests.

Overview
Fixes inconsistent finding counts when multiple notifier workers process the same scan result at once.

The notifier dedupes non-reverification results (SecretID == 0) via a shared LRU cache keyed by an MD5 of detector name, type, raw secret, and source metadata. That path used a separate lookup then insert, so two workers could both see a miss and dispatch the same finding twice. The change replaces that with ContainsOrAdd so check-and-insert is one step, with a short comment that the cache is shared across workers.

Tests add a mutex on captureDispatcher for concurrent notifier use, and TestNotifierWorker_ConcurrentDuplicatesDispatchedOnce runs 16 workers over 1,000 distinct secrets with 16 copies each (cache sized to avoid eviction) and asserts exactly one dispatch per secret.

Reviewed by Cursor Bugbot for commit 5c5e416. Bugbot is set up for automated code reviews on this repo. Configure here.

@kvnphvm
kvnphvm requested a review from a team September 26, 2026 06:37
@kvnphvm
kvnphvm requested a review from a team as a code owner September 26, 2026 06:37
@kvnphvm
kvnphvm merged commit 5d8d4a3 into main Sep 30, 2026
16 checks passed
@kvnphvm
kvnphvm deleted the int-1085-resolve-race-condition-in-result-deduplication-cache branch September 30, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants