[Checkins] SVN: zope.locking/trunk/src/zope/locking/ Fix issue in
cleaning up expired lock tokens. The cleanup method was modifying
Michael Kerrin
michael.kerrin at openapp.ie
Tue May 22 12:11:15 EDT 2007
Log message for revision 75884:
Fix issue in cleaning up expired lock tokens. The cleanup method was modifying
a OOBTree instance while it was iterating over it.
Changed:
U zope.locking/trunk/src/zope/locking/cleanup.txt
U zope.locking/trunk/src/zope/locking/utility.py
-=-
Modified: zope.locking/trunk/src/zope/locking/cleanup.txt
===================================================================
--- zope.locking/trunk/src/zope/locking/cleanup.txt 2007-05-22 16:04:27 UTC (rev 75883)
+++ zope.locking/trunk/src/zope/locking/cleanup.txt 2007-05-22 16:11:15 UTC (rev 75884)
@@ -325,13 +325,40 @@
>>> list(util._expirations[new_lock.expiration]) == [new_lock]
True
+An issue arose when two or more expired locks are stored in the utility. When
+we tried to add a third lock token the cleanup method incorrectly tried to
+clean up the the lock token we were trying to add.
+
+ >>> second_demo = Demo()
+ >>> second_lock = util.register(
+ ... tokens.ExclusiveLock(second_demo, 'john', THREE_HOURS))
+
+ >>> len(util._expirations)
+ 2
+
+Now expire the two registered tokens. The offset is currently 3 hours from now
+and the tokens have a duration of 3 hours so increase by 7 hours.
+
+ >>> offset = THREE_HOURS + FOUR_HOURS
+
+Register the third lock token.
+
+ >>> third_demo = Demo()
+ >>> third_lock = util.register(
+ ... tokens.ExclusiveLock(third_demo, 'michael', ONE_HOUR))
+
+ >>> len(util._expirations)
+ 1
+ >>> list(util._expirations[third_lock.expiration]) == [third_lock]
+ True
+
Explicit Ending
---------------
If I end all the tokens, it should remove all records from the indexes.
>>> freeze.end()
- >>> new_lock.end()
+ >>> third_lock.end()
>>> len(util._locks)
0
>>> len(util._principal_ids)
Modified: zope.locking/trunk/src/zope/locking/utility.py
===================================================================
--- zope.locking/trunk/src/zope/locking/utility.py 2007-05-22 16:04:27 UTC (rev 75883)
+++ zope.locking/trunk/src/zope/locking/utility.py 2007-05-22 16:11:15 UTC (rev 75884)
@@ -39,6 +39,7 @@
def _cleanup(self):
"clean out expired keys"
+ expiredkeys = []
for k in self._expirations.keys(max=utils.now()):
for token in self._expirations[k]:
assert token.ended
@@ -46,6 +47,8 @@
self._del(self._principal_ids, token, p)
key_ref = IKeyReference(token.context)
del self._locks[key_ref]
+ expiredkeys.append(k)
+ for k in expiredkeys:
del self._expirations[k]
def register(self, token):
More information about the Checkins
mailing list