Author: mtredinnick
Date: 2008-08-27 03:58:51 -0500 (Wed, 27 Aug 2008)
New Revision: 8620

Modified:
   django/trunk/django/contrib/sessions/backends/cache.py
Log:
Fixed #8311 -- Avoid an infinite loop with session key generation when using
the cache backend and memcached goes away (or is not running).


Modified: django/trunk/django/contrib/sessions/backends/cache.py
===================================================================
--- django/trunk/django/contrib/sessions/backends/cache.py      2008-08-27 
08:51:35 UTC (rev 8619)
+++ django/trunk/django/contrib/sessions/backends/cache.py      2008-08-27 
08:58:51 UTC (rev 8620)
@@ -17,7 +17,12 @@
         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 @@
                 continue
             self.modified = True
             return
+        raise RuntimeError("Unable to create a new session key.")
 
     def save(self, must_create=False):
         if must_create:


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to