fix: bound mapper cache and reuse host regexes - #262
Merged
Conversation
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.
Reported by @paskal.
mappersCachehad 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:findMatchingMapperscompiles each non-default key as an unanchored regex, so a configuration whose only server isexample.comstill 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
Hostvalues against a wildcard route, RSS delta immediately after each run: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.