Download vuls2 database (if enabled) on startup - #2618
Open
maxenced wants to merge 2 commits into
Open
Conversation
…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.
Author
|
Image built with both PR available here : ghcr.io/maxenced/vuls:a7e6db930e0280f6eca606ded04754759c7db220 Result is : The healthcheck and /vuls endpoints now switch to 200/ok and normal behavior. Then we get requests |
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note : This PR is based on #2617
The issue it solves is that with current behaviour, on startup :
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:
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.