Skip to content

Download vuls2 database (if enabled) on startup - #2618

Open
maxenced wants to merge 2 commits into
future-architect:masterfrom
maxenced:fix/download_on_startup
Open

Download vuls2 database (if enabled) on startup#2618
maxenced wants to merge 2 commits into
future-architect:masterfrom
maxenced:fix/download_on_startup

Conversation

@maxenced

Copy link
Copy Markdown

Note : This PR is based on #2617

The issue it solves is that with current behaviour, on startup :

  • vuls2 database is not fetched
  • the healthcheck becomes ready
  • When first bunch of requests are made, each one starts a new download (which takes more than the client can wait)

The new behavior is :

On server startup, if vuls2 is configured and skipUpdate is not set,
trigger a background download of the database immediately. Until the
download completes:

  • /health returns 503 with body "downloading vuls2"
  • /vuls returns 503 and does not trigger a redundant download

Once the initial fetch succeeds, both endpoints resume normal operation.
If the DB already exists with a valid schema at startup, readiness is
immediate and only a background staleness refresh is triggered.

This ensures Kubernetes/load-balancer health checks keep the server out
of rotation until it can actually serve vulnerability data, while
avoiding thundering-herd downloads from concurrent requests.

maxenced added 2 commits July 29, 2026 13:52
…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.
On server startup, if vuls2 is configured and skipUpdate is not set,
trigger a background download of the database immediately. Until the
download completes:

- /health returns 503 with body "downloading vuls2"
- /vuls returns 503 and does not trigger a redundant download

Once the initial fetch succeeds, both endpoints resume normal operation.
If the DB already exists with a valid schema at startup, readiness is
immediate and only a background staleness refresh is triggered.

This ensures Kubernetes/load-balancer health checks keep the server out
of rotation until it can actually serve vulnerability data, while
avoiding thundering-herd downloads from concurrent requests.
@maxenced

Copy link
Copy Markdown
Author

Image built with both PR available here : ghcr.io/maxenced/vuls:a7e6db930e0280f6eca606ded04754759c7db220

Result is :

vulsio-1  | time="Jul 29 14:20:44" level=info msg="Validating config..."
vulsio-1  | time="Jul 29 14:20:44" level=info msg="Starting initial vuls2 db download. repository: ghcr.io/vulsio/vuls-nightly-db:nightly"
vulsio-1  | time="Jul 29 14:20:44" level=info msg="Listening on :80"
⠼ fetching (12 GB, 282 MB/s) [42s]
vulsio-1  | time="Jul 29 14:21:40" level=info msg="Initial vuls2 db fetch completed successfully" 

The healthcheck and /vuls endpoints now switch to 200/ok and normal behavior. Then we get requests

vulsio-1  | time="Jul 29 14:22:30" level=info msg="5820 CVEs are detected with vuls2 (os packages)"

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