Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some memory leaks in TTL implementation #358

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Woutifier
Copy link

The aim of this PR is to resolve three issues with the Ristretto TTL implementation:

  • Expiry cleanup is not guaranteed to run, if it doesn't run when expected memory is leaked
  • expiryMap isn't cleared when cache is cleared
  • on Update items are added into the expiryMap even if they have no TTL set

Expiry cleanup is not guaranteed to run at any interval. It attemps to
run roughly twice per bucket duration, but may in fact not run.

If the cleanup does not run at least one per bucket duration, one or
more buckets may be leaked.

This commit adds a field lastCleanedBucketNum to the expirationMap to
keep track of the last bucket that was cleaned up. When cleanup is
called will clean up all the buckets between the last bucket and the
current bucket.
@CLAassistant
Copy link

CLAassistant commented Sep 29, 2023

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

…o expiration

If an item was already in the cache, adding it again will cause it to be
added into the expiration map, even if the item has no expiration set.

This effectively is a memory leak. There is no clean up of this "zero
time" bucket, and it will keep growing.
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.

None yet

2 participants