⚡ Bolt: Prevent L1 cache memory exhaustion via FIFO size limit - #20
⚡ Bolt: Prevent L1 cache memory exhaustion via FIFO size limit#20suranig wants to merge 2 commits into
Conversation
Added a MAX_L1_CACHE_SIZE limit to the L1 in-memory cache to prevent memory exhaustion DoS when caching numerous distinct keys. Implemented a fast FIFO eviction policy using Map.prototype.keys().next().value. Co-authored-by: suranig <24814104+suranig@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Added a MAX_L1_CACHE_SIZE limit to the L1 in-memory cache to prevent memory exhaustion DoS when caching numerous distinct keys. Implemented a fast FIFO eviction policy using Map.prototype.keys().next().value. Includes test coverage for the eviction behavior. Co-authored-by: suranig <24814104+suranig@users.noreply.github.com>
💡 What: Introduced a
MAX_L1_CACHE_SIZEof 1000 items and implemented an O(1) FIFO eviction policy usingMap.prototype.keys().next().valueto manage the L1 in-memory cache safely.🎯 Why: Without a size limit, the in-memory
Mapcould grow indefinitely when handling requests with dynamically generated, distinct cache keys. This risks memory exhaustion leading to degraded application performance due to excessive garbage collection, or potentially causing application crashes from Out-Of-Memory (OOM) errors (a form of Denial of Service vector).📊 Impact: Prevents memory leaks on the L1 cache. The application's memory usage is now strictly bounded for in-memory caching overhead.
🔬 Measurement: Verify by examining test suite execution and confirming no memory-related regression. Long-running profiles on heavily trafficked endpoints with randomized cache keys will confirm bounded memory allocation.
PR created automatically by Jules for task 934691618872139084 started by @suranig