fix(oas-validator): negatively cache spec_url fetch failures#13585
Open
AlinsRan wants to merge 1 commit into
Open
fix(oas-validator): negatively cache spec_url fetch failures#13585AlinsRan wants to merge 1 commit into
AlinsRan wants to merge 1 commit into
Conversation
When spec_url is configured, a fetch or compile failure was not cached, so a persistently failing spec_url triggered an outbound HTTP request on every incoming request (failure amplification). Add neg_ttl/neg_count to the spec lru cache so failures are cached for a short window (5s), while a recovered spec_url is still picked up quickly. Add a test asserting a failing spec_url is fetched once across several requests. Signed-off-by: AlinsRan <alinsran@apache.org>
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.
Description
When
oas-validatorloads the OpenAPI spec fromspec_url, a fetch/compile failure was not cached. A persistently failingspec_url(remote down, non-200, invalid JSON) therefore triggered an outbound HTTP request on every incoming request — failure amplification that piles up connections and latency during an outage.This adds
neg_ttl/neg_countto the spec lru cache so failures are cached for a short window (5s).core.lrucachechecks the negative cache before invoking the fetch, so repeated requests return the cached error without re-fetching, while a recoveredspec_urlis still picked up within 5s. The route still returns 500 on failure — only the redundant outbound fetches are eliminated.Tests
t/plugin/oas-validator3.tTEST 24/25: a route whosespec_urlalways returns 404 is hit 3 times; a shared-dict counter on the spec endpoint asserts it was fetched once.Checklist