[CalendarServer-changes] [1845] CalendarServer/trunk/twistedcaldav/directory/digest.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Sep 6 11:50:25 PDT 2007


Revision: 1845
          http://trac.macosforge.org/projects/calendarserver/changeset/1845
Author:   cdaboo at apple.com
Date:     2007-09-06 11:50:24 -0700 (Thu, 06 Sep 2007)

Log Message:
-----------
Fix a race condition where two server machine would stomp over each others use of the credentials db and would result in
corruption of the db file. Now we no longer delete the db file on startup - instead we run a 'cleanup' on it to remove
stale records. Also the clean-up code was changed to handle possible race-conditions with multiple processes calling
it simulataneously. Last fix was to remove uneeded commit statements as the autoCommit option is set on the db connection.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/directory/digest.py

Modified: CalendarServer/trunk/twistedcaldav/directory/digest.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/digest.py	2007-09-06 16:07:14 UTC (rev 1844)
+++ CalendarServer/trunk/twistedcaldav/directory/digest.py	2007-09-06 18:50:24 UTC (rev 1845)
@@ -162,8 +162,6 @@
 
     def __init__(self, path):
         db_path = os.path.join(path, DigestCredentialsDB.dbFilename)
-        if os.path.exists(db_path):
-            os.remove(db_path)
         super(DigestCredentialsDB, self).__init__(db_path, autocommit=True)
         self.exceptions = 0
     
@@ -268,7 +266,6 @@
             values (:1, :2)
             """, (key, value,)
         )
-        self._db_commit()
        
     def _delete_from_db(self, key):
         """
@@ -277,7 +274,6 @@
         @param key: the key to remove.
         """
         self._db().execute("delete from DIGESTCREDENTIALS where KEY = :1", (key,))
-        self._db_commit()
     
     def _db_version(self):
         """
@@ -336,6 +332,9 @@
         super(QopDigestCredentialFactory, self).__init__(algorithm, realm)
         self.qop = qop
         self.db = DigestCredentialsDB(db_path)
+        
+        # Always clean-up when we start-up
+        self.cleanup()
 
     def getChallenge(self, peer):
         """
@@ -500,6 +499,13 @@
         keys = self.db.keys()
         oldest_allowed = time.time() - DigestCredentialFactory.CHALLENGE_LIFETIME_SECS
         for key in keys:
-            ignore_clientip, ignore_cnonce, db_timestamp = self.db.get(key)
-            if db_timestamp <= oldest_allowed:
-                self.invalidate(key)
+            try:
+                value = self.db.get(key)
+                if value is not None:
+                    ignore_clientip, ignore_cnonce, db_timestamp = value
+                    if db_timestamp <= oldest_allowed:
+                        self.invalidate(key)
+            except Exception, e:
+                # Clean-up errors can be logged but we should ignore them
+                log.err("Error cleaning digest credentials: %s" % (e,))
+                pass

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070906/d3652b40/attachment.html


More information about the calendarserver-changes mailing list