# HG changeset patch # User Paul Boddie # Date 1446831273 -3600 # Node ID cad23243f170b78e48a74b8df43a9542293efcca # Parent e81fe95cfbd68e400651ab81011327d6f280b1e0 Adopted unique "old" lock directory names to prevent race conditions causing exceptions and locks being left in place. diff -r e81fe95cfbd6 -r cad23243f170 imiptools/filesys.py --- a/imiptools/filesys.py Fri Nov 06 17:17:22 2015 +0100 +++ b/imiptools/filesys.py Fri Nov 06 18:34:33 2015 +0100 @@ -172,10 +172,16 @@ parts = parts and list(parts) or [] target = parts[:] - # Move the directory. + # Move the directory to a unique name. This prevents unlikely but + # possible conflicts as a slow unlocking process is caught up by a + # following, faster locking-then-unlocking process which would then + # try and rename the active lock directory to a common old lock + # directory name, causing a "directory not empty" exception and the + # continued existence of the lock. parts.append(self.lock_name) - target.append(self.old_lock_name) + old_lock_name = "%s.%d" % (self.old_lock_name, getpid()) + target.append(old_lock_name) rename(self.get_object_in_store(*parts), self.get_object_in_store(*target)) # Then remove the moved directory and its contents.