Repository navigation
fix: bound enrichment caches to prevent unbounded memory growth (LAN-145) - #115
Merged
Merged
Conversation
…145) Add prune_cache helper in lookup/mod.rs that performs two-phase eviction: 1. Drop TTL-expired entries (cached_at + ttl has elapsed) 2. If still over ENRICHMENT_CACHE_CAP (10,000), evict oldest by cached_at Apply to all four enrichment caches: - ASN (src/lookup/asn.rs): prune after insert in lookup() - rDNS (src/lookup/rdns.rs): prune after insert in reverse_lookup() - Geo (src/lookup/geo.rs): prune after insert in lookup() - IX (src/lookup/ix.rs): prune after insert in lookup(), merge dual ip_cache + ip_cache_times maps into single HashMap<IpAddr, IpCacheEntry> to eliminate the dual-map sync hazard and simplify eviction CAP rationale: 64 max TTL × ~3 responders/hop × 10 targets = ~2,000 IPs. 10,000 gives 5× headroom while preventing pathological growth.
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
Closes LAN-145 (#11: unbounded enrichment caches).
All four enrichment caches (ASN, rDNS, Geo, IX) were unbounded
HashMap<IpAddr, _>s — they inserted entries with timestamps but never evicted. Long-running sessions accumulated memory indefinitely.Changes
Shared helper (
src/lookup/mod.rs):prune_cache()— two-phase eviction:cached_at + ttlelapsed)ENRICHMENT_CACHE_CAP(10,000), evict oldest bycached_atENRICHMENT_CACHE_CAP = 10_000— 64 max TTL × ~3 responders/hop × 10 targets ≈ 2,000 IPs; cap gives 5× headroomPer-module — call
prune_cacheafter each insert:src/lookup/asn.rs— ASN cachesrc/lookup/rdns.rs— rDNS cachesrc/lookup/geo.rs— GeoIP cachesrc/lookup/ix.rs— IX per-IP cache; merged dualip_cache+ip_cache_timesmaps into singleHashMap<IpAddr, IpCacheEntry>to eliminate the dual-map sync hazard and simplify evictionTests
4 new tests in
lookup::tests:test_prune_removes_expired_entries— phase 1: TTL expirytest_prune_keeps_all_when_under_and_fresh— no-op when under captest_prune_phase2_evicts_oldest— phase 2: over-cap evicts oldest 3 (10,003 entries → 10,000, oldest 3 removed)test_prune_empty_cache_is_noop— empty cacheAll 593 tests pass, clippy clean.