summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-08-27 08:58:51 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-08-27 08:58:51 +0000
commitee28560997e324203333b891e488b2d2d7c9511d (patch)
tree073b602ec7dd707bdc37a37491d38890dd0de729
parentb80db03ca728c70f2018bdaf745fa389dea5410e (diff)
Fixed #8311 -- Avoid an infinite loop with session key generation when using
the cache backend and memcached goes away (or is not running). git-svn-id: http://code.djangoproject.com/svn/django/trunk@8620 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/sessions/backends/cache.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/django/contrib/sessions/backends/cache.py b/django/contrib/sessions/backends/cache.py
index 94ae448a1f..5fdf133b05 100644
--- a/django/contrib/sessions/backends/cache.py
+++ b/django/contrib/sessions/backends/cache.py
@@ -17,7 +17,12 @@ class SessionStore(SessionBase):
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()
try:
self.save(must_create=True)
@@ -25,6 +30,7 @@ class SessionStore(SessionBase):
continue
self.modified = True
return
+ raise RuntimeError("Unable to create a new session key.")
def save(self, must_create=False):
if must_create: