Repository navigation
Replies: 2 comments
|
Hello @sbley, thanks for the detailed analysis and the reproduction script! Your analysis is correct. For now, I suggest working around it in one of these ways:
Fixing this on the Trivy side is possible, but not as simple as it looks. This is the first report where the root cause is confirmed, and there is a simple workaround for this scenario, so we'll keep this discussion open to collect feedback: if you or other users run into this issue too, please add a 👍 or describe your scenario in the comments. Regards, Dmitriy |
|
Thanks for confirming the cause and for the workarounds. We now run the parallel scans of one Git hook one after the other, so a single run downloads the DB only once. The workaround doesn't cover separate processes that share It happens rarely, about once a day at most, and the push passes when you retry it. So for now we're keeping our current setup. If it gets fixed in Trivy, a file lock around the download and unpack in the cache directory would be enough for our case, without the extra disk space for a temporary copy. |
Uh oh!
There was an error while loading. Please reload this page.
Description
Two Trivy processes that share a cache directory and both need the vulnerability DB (none cached yet, or the cached one out of date) download it at the same time. If the second one starts unpacking while the first is still unpacking, the first one crashes with SIGBUS (or SIGSEGV) when it reads the DB.
We hit it in a Git pre-push hook that runs
trivy fs --scanners vulnon two directories in parallel, on the first push with an empty cache. This looks like the same crash as #10283 ((*Page).FastCheckin bbolt, fresh cache, two Trivy processes in parallel), which was closed without a root cause. It is related to #8454, fixed in #8452, where parallel downloads left an empty DB.What happens, in
pkg/downloader/download.goand go-getter:db.tar.gzinto their own temp directories.os.RemoveAll(<cache>/db), then go-getter unpackstrivy.dbinto<cache>/db, thenmetadata.json.trivy.db, Y installs its download: it removes<cache>/db, with X's half-written file, and starts writing a newtrivy.db.metadata.jsoninto Y's new directory, and opens<cache>/db/trivy.dbread-only. That is Y's partial file.A process that already has the old DB open is not affected: the removal leaves its file intact.
The troubleshooting guide says the vulnerability DB is opened read-only and does not cause lock issues, and
fsuses the memory scan cache by default, so we expected paralleltrivy fsruns to be safe.Desired Behavior
Parallel runs that share a cache directory either download the DB once, or each one reads a complete DB. For example, the DB is unpacked into a temporary directory inside the cache directory and renamed into place, so a reader never opens a partial file, and/or a file lock around
DownloadDBserializes the download across processes.If parallel runs that download the DB are not supported, a note in the troubleshooting guide would help, for example to run
trivy fs --download-db-onlyfirst and the parallel scans with--skip-db-update.Actual Behavior
The process whose download finishes first crashes:
Reproduction Steps
The race is narrow when the processes run freely: two runs started at the same moment crashed once in 10 attempts. The script forces the interleaving by pausing X while it unpacks and Y after it has replaced X's file and written more than 1 GB, then lets X continue.
scan/is any directory with a lock file whose packages Trivy looks up; we used apnpm-lock.yamlwith--include-dev-deps. It needs about 4 GB of free disk in the cache directory.Target
Filesystem
Scanner
Vulnerability
Output Format
JSON
Mode
Standalone
Debug Output
Of process X:
Operating System
Ubuntu 26.04.1 LTS, arm64, Linux 6.18 (devcontainer). First seen in a devcontainer on macOS with Rancher Desktop, also arm64.
Version
Checklist
trivy clean --all(the reproduction uses its own new cache directory)All reactions