Fix memory leak on flush method for TaggableStore #48101
Closed
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.
#48100
Currently when calling
flush()on aTaggableStore, all that happens is the namespace is reset, meaning the reference to any cached data is lost, and any further cache reads miss.This however leads to the data staying in the store, and therefore gradually leaking memory - this is problematic in long running processes for example and can lead to unpredictable crashes.
The approach here is to keep an additional cache entry:
<namespace>:meta:entriesconsisting of a list of keys within the tag, and on callingflush()looping through these keys and removing them from the store.As it happens the RedisTaggedCache/RedisTagSet already has similar behaviour, so I have not applied this new logic there.