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

handling memcache failures #78

Closed
wants to merge 1 commit into from
Closed

handling memcache failures #78

wants to merge 1 commit into from

Conversation

tzachyrm
Copy link

Some memcached backeds return False from the add function due to sporadic failures. In this case the following call to incr will raise a ValueError, and the call to get will return None.

count = cache.incr(cache_key)
try:
count = cache.incr(cache_key)
except ValueError: # add failed or value expired
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Comments require two space before them when they're inline like this.

@willkg
Copy link
Collaborator

willkg commented Aug 27, 2015

When you say "some memcached backends", which ones are you talking about specifically? Are there links to documentation about the issue?

@adamchainz
Copy link
Collaborator

This affected us @YPlan too 😄

The cause of this is not 'sporadic', but a race condition with evictions; add() returns False since the key is there when it checks, but by the time incr() or get() runs, the key has been evicted due to other parallel traffic, or expired. This is only something you'd see with enough traffic.

The ValueError-on-failed-incr() behaviour is for all Django built-in memcached backends - the behaviour is normalized in BaseMemcachedCache: https://github.com/django/django/blob/master/django/core/cache/backends/memcached.py#L105

We are currently using a similar patch like this one but with some tests 😄 I've submitted it as a second PR here: #81

@tzachyrm
Copy link
Author

tzachyrm commented Sep 6, 2015

@willkg In my case it's the Google App Engine memcache. The docs state that:

Memcache operations can fail for various reasons. Applications should be designed to catch failed operations without exposing these errors to end users. This applies especially to Set operations.

@jsocol
Copy link
Owner

jsocol commented Oct 14, 2015

Closing in favor of #81 (which itself may be fixed)

@jsocol jsocol closed this Oct 14, 2015
@jsocol
Copy link
Owner

jsocol commented Oct 14, 2015

@adamchainz et al, can you check to see if #88 fixed this for you?

@adamchainz
Copy link
Collaborator

Yes it did./

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.

4 participants