🧹 fix: unmanaged setInterval causes memory leak - #12
Conversation
Add a `destroy` method to `CacheHandler` to clear `cleanupInterval` and `l1Cache`. Store the `setInterval` in a variable and call `unref` on it to ensure it does not prevent Node process from exiting. 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❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
- Implement `destroy()` in `createCacheHandler` to stop `cleanupInterval` - Add optional `destroy` method to `CacheHandler` type - Ensure temporary cache handlers in `fetchWithCache` invoke `destroy()` in a finally block to prevent intervals from piling up - Fix `no-console` and `no-non-null-assertion` lint rules in `src/backends/index.ts` Co-authored-by: suranig <24814104+suranig@users.noreply.github.com>
🎯 What: An unmanaged
setIntervalfor L1 cache cleanup caused a potential memory leak and kept the Node.js process alive.💡 Why: By storing the interval and unref'ing it, as well as providing an explicit
destroymethod on the returned cache handler, the caller has the ability to manage the lifecycle of the cache handler. This improves maintainability and correctly prevents memory leaks.✅ Verification: A test case was added to verify
destroyclears the interval correctly. Full vitest suite was run to ensure no regressions. Linter and formatter also applied and successfully run.✨ Result: A robust resource lifecycle where cleanup intervals don't cause side-effects.
PR created automatically by Jules for task 15846621255395477825 started by @suranig