Browse files

Fixed #8311 -- Avoid an infinite loop with session key generation whe…

…n using

the cache backend and memcached goes away (or is not running).

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent b80db03 commit ee28560997e324203333b891e488b2d2d7c9511d @malcolmt malcolmt committed Aug 27, 2008
Showing with 7 additions and 1 deletion.
  1. +7 −1 django/contrib/sessions/backends/
@@ -17,14 +17,20 @@ def load(self):
return {}
def create(self):
- while True:
+ # Because a cache can fail silently (e.g. memcache), we don't know if
+ # we are failing to create a new session because of a key collision or
+ # because the cache is missing. So we try for a (large) number of times
+ # and then raise an exception. That's the risk you shoulder if using
+ # cache backing.
+ for i in xrange(10000):
self.session_key = self._get_new_session_key()
except CreateError:
self.modified = True
+ raise RuntimeError("Unable to create a new session key.")
def save(self, must_create=False):
if must_create:

0 comments on commit ee28560

Please sign in to comment.