Skip to content

🧹 fix: unmanaged setInterval causes memory leak - #12

Merged
suranig merged 2 commits into
masterfrom
fix-memory-leak-15846621255395477825
Apr 23, 2026
Merged

🧹 fix: unmanaged setInterval causes memory leak#12
suranig merged 2 commits into
masterfrom
fix-memory-leak-15846621255395477825

Conversation

@suranig

@suranig suranig commented Apr 19, 2026

Copy link
Copy Markdown
Owner

🎯 What: An unmanaged setInterval for 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 destroy method 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 destroy clears 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

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>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

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

codecov Bot commented Apr 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.30508% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/backends/index.ts 93.75% 1 Missing ⚠️

📢 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>
@suranig
suranig merged commit 942d81d into master Apr 23, 2026
4 checks passed
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.

1 participant