1. Andrew Godwin
  2. django


mtre...@bcc190cf-cafb-0310-a4f2-bffc1f526a37  committed 2f317db

Fixed #8311 -- Avoid an infinite loop with session key generation when using
the cache backend and memcached goes away (or is not running).

  • Participants
  • Parent commits c1e18ce
  • Branches default

Comments (0)

Files changed (1)

File django/contrib/sessions/backends/cache.py

View file
         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()
             self.modified = True
+        raise RuntimeError("Unable to create a new session key.")
     def save(self, must_create=False):
         if must_create: