Skip to content

fix(detector/vuls2): prevent redundant parallel DB downloads in server mode - #2617

Open
maxenced wants to merge 1 commit into
future-architect:masterfrom
maxenced:fix/async-single-flight-db-download
Open

fix(detector/vuls2): prevent redundant parallel DB downloads in server mode#2617
maxenced wants to merge 1 commit into
future-architect:masterfrom
maxenced:fix/async-single-flight-db-download

Conversation

@maxenced

Copy link
Copy Markdown

As discussed in #2613 , vuls2 has no limit on concurrent download when multiple HTTP requests arrive while the vuls2 database is stale, each one independently triggered a full download from the OCI registry. This wasted bandwidth, disk and I/O without any coordination.

This introduce a single-flight async background fetch mechanism: the first request that detects a stale DB spawns an async goroutine to download the update while immediately serving from the current (stale) DB. All concurrent requests that arrive while the download is in flight skip the fetch and use the existing DB.

This does not fix startup download (which will be part of another PR)

Safety guarantees are maintained: if the background fetch fails, temp files are cleaned up by the upstream fetch library and the lock is released so the next request can retry.

Is this ready for review?: YES

…r mode

When multiple HTTP requests arrive while the vuls2 database is stale,
each one independently triggered a full download from the OCI registry.
This wasted bandwidth and I/O without any coordination.

Introduce a single-flight background fetch mechanism: the first request
that detects a stale DB spawns an async goroutine to download the update
while immediately serving from the current (stale) DB. All concurrent
requests that arrive while the download is in flight skip the fetch and
use the existing DB.

Synchronous (blocking) downloads are preserved for cases where the
current DB cannot be used at all: first-ever download or schema version
mismatch.

Safety guarantees are maintained: if the background fetch fails, temp
files are cleaned up by the upstream fetch library and the lock is
released so the next request can retry.
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.

1 participant