fix(detector/vuls2): share opened db session across server requests#2544
Closed
MaineK00n wants to merge 1 commit into
Closed
fix(detector/vuls2): share opened db session across server requests#2544MaineK00n wants to merge 1 commit into
MaineK00n wants to merge 1 commit into
Conversation
Per-request bolt.Open() on the vuls2 BoltDB acquired the OS-level file lock and rebuilt the WithCache:true session cache on every HTTP request, serializing concurrent `vuls server` requests and causing minutes-long latency at concurrency >= 4-5 (#2542). Each request opened the file four times: twice in newDBConfig (validate-then-close, then again for the caller) for both Detect and EnrichVulnInfos. Open the session lazily on first use, validate metadata once, and reuse the same opened session for subsequent callers. Server mode closes the cached session at shutdown via the new vuls2.CloseSession.
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.
Summary
vuls serverwith the vuls2 BoltDB backend hung for several minutes once concurrency reached ~4-5.newDBConfigvalidation, plus the caller's session in bothDetectandEnrichVulnInfos). Every open acquires the OS-level file lock and rebuilds theWithCache: truesession cache, so concurrent requests serialized against each other.vuls2.CloseSession.Why only vuls2
go-cve-dictionaryandgostfollow the same per-request open/close pattern, but their backends sidestep the cost (Redis / HTTP / SQLite3-with-WAL / RDBMS connection pools), so the issue does not manifest in practice. vuls2 is BoltDB-only and additionally re-initializes aWithCache: truecache per open, making the per-request pattern a real bottleneck — hence the targeted fix here.When
cveDict/gostare eventually folded into vuls2 (à lago-msfdb/go-exploitdb), the natural follow-up is to expose the session as an explicit argument and remove the package-level cache; today's internalgetSessiondoes not lock that direction in.Trade-offs / notes
SkipUpdate = falsewill hold the db opened at startup for the lifetime of the process. This matches today's effective behavior (the per-request opens still saw only the snapshot they validated against) and is consistent with the existing recommendation to useSkipUpdate = truein server mode.CloseSessionis invoked fromsubcmds/server.goviadefer. Process termination by signal will not run the defer, but the OS releases the BoltDB file lock on exit anyway — adding a signal handler is out of scope for this fix.Test plan
go build ./...go vet ./detector/vuls2/... ./subcmds/... ./server/...go test ./detector/vuls2/...vuls serveragainst a real vuls2 db, fire concurrent requests (e.g.seq 1 8 | xargs -P8 -I{} curl -X POST ...) and confirm response time stays roughly linear in payload size rather than blowing up with concurrency.🤖 Generated with Claude Code