kiddouk / redisco

A Python Library for Simple Models and Containers Persisted in Redis
MIT License
438 stars 78 forks source link

Memory Leak - Redisco doesn't delete filter keys properly #10

Closed kiddouk closed 12 years ago

kiddouk commented 12 years ago

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.

kiddouk commented 12 years ago

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

kiddouk commented 12 years ago

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