Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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: http://code.djangoproject.com/svn/django/trunk@8620 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ee28560997e324203333b891e488b2d2d7c9511d 1 parent b80db03
Malcolm Tredinnick authored August 27, 2008
8  django/contrib/sessions/backends/cache.py
@@ -17,7 +17,12 @@ def load(self):
17 17
         return {}
18 18
 
19 19
     def create(self):
20  
-        while True:
  20
+        # Because a cache can fail silently (e.g. memcache), we don't know if
  21
+        # we are failing to create a new session because of a key collision or
  22
+        # because the cache is missing. So we try for a (large) number of times
  23
+        # and then raise an exception. That's the risk you shoulder if using
  24
+        # cache backing.
  25
+        for i in xrange(10000):
21 26
             self.session_key = self._get_new_session_key()
22 27
             try:
23 28
                 self.save(must_create=True)
@@ -25,6 +30,7 @@ def create(self):
25 30
                 continue
26 31
             self.modified = True
27 32
             return
  33
+        raise RuntimeError("Unable to create a new session key.")
28 34
 
29 35
     def save(self, must_create=False):
30 36
         if must_create:

0 notes on commit ee28560

Please sign in to comment.
Something went wrong with that request. Please try again.