kiddouk / redisco

A Python Library for Simple Models and Containers Persisted in Redis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory Leak - Redisco doesn't delete filter keys properly

kiddouk opened this issue · comments

Considering the following code :

class A(models.Model):
   att = models.Attribute()

class B(models.Model):
   a = models.ReferenceField()

a = A()
a.att = "test"
a.save()

b = B()
b.a = a
b.save()

B.objects.filter(a_id=a.id)
# Here redis doesn't delete the filter keys as "_expire_or_delete" should. Leaking 2 more keys in the DB.

Redisco end up leaking 2 filter keys (best case) and n filtering keys in case of multiple filtering.

Suggestion

give a timeout to each temporary keys to let say 60 seconds. It will give time to the operation to succeed and let redis handle the clean up for us.

Moreover, issuing an EXPIRE command is as costly as ISSUING a DEL command and reduces the logic inside redisco.

This fix has obviously some implications:

You can't use your modelset for more than a minute.
example :

cool_users = User.objects.filter(name="Jakub")
# wait one minute
len(cool_users) == 0
# True