Skip to content

fix: bound mapper cache and reuse host regexes - #262

Merged
umputun merged 1 commit into
masterfrom
fix/bound-mappers-cache
Aug 21, 2026
Merged

fix: bound mapper cache and reuse host regexes#262
umputun merged 1 commit into
masterfrom
fix/bound-mappers-cache

Conversation

@umputun

@umputun umputun commented Aug 21, 2026

Copy link
Copy Markdown
Owner

Reported by @paskal. mappersCache had no size limit and no eviction, and was written for every distinct host reaching the pattern-matching path. A server key that looks concrete is not treated as one: findMatchingMappers compiles each non-default key as an unanchored regex, so a configuration whose only server is example.com still caches every host containing that substring. The cache is written before any path matching, auth or throttling runs, so a request that ends in 502 still costs a permanent entry.

The cache is now a fixed 1024-entry LRU, and each server key's regex compiles once when the mapper table is installed rather than on every cache miss. Without that second half a capped cache would just move the attack from memory to CPU.

Measured with distinct Host values against a wildcard route, RSS delta immediately after each run:

              50k hosts    150k hosts
master          17.2 MB       41.1 MB
branch           8.7 MB       10.0 MB

Master's retention scales with the request count; here it does not, and the residual is transient allocation rather than retained entries.

Exact, wildcard, catch-all and unanchored-regex matching are all unchanged, and no metrics behaviour changes. Server keys are deliberately not anchored: that would change route matching for every existing configuration.

Copilot AI lite review requested due to automatic review settings August 21, 2026 00:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@umputun
umputun merged commit 43daa21 into master Aug 21, 2026
4 checks passed
@umputun
umputun deleted the fix/bound-mappers-cache branch August 21, 2026 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants