Skip to content

fix(oas-validator): negatively cache spec_url fetch failures#13585

Open
AlinsRan wants to merge 1 commit into
apache:masterfrom
AlinsRan:fix/oas-validator-spec-url-negative-cache
Open

fix(oas-validator): negatively cache spec_url fetch failures#13585
AlinsRan wants to merge 1 commit into
apache:masterfrom
AlinsRan:fix/oas-validator-spec-url-negative-cache

Conversation

@AlinsRan

Copy link
Copy Markdown
Contributor

Description

When oas-validator loads the OpenAPI spec from spec_url, a fetch/compile failure was not cached. A persistently failing spec_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_count to the spec lru cache so failures are cached for a short window (5s). core.lrucache checks the negative cache before invoking the fetch, so repeated requests return the cached error without re-fetching, while a recovered spec_url is still picked up within 5s. The route still returns 500 on failure — only the redundant outbound fetches are eliminated.

Tests

t/plugin/oas-validator3.t TEST 24/25: a route whose spec_url always returns 404 is hit 3 times; a shared-dict counter on the spec endpoint asserts it was fetched once.

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change (N/A — internal caching, no config/behavior change)
  • I have verified that this change is backward compatible

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>
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant