Commit 71e1863e authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

locking: Fix race condition in LockSet



This patch fixes a race condition when acquiring all locks in
a LockSet instance. The list of lock names needs to be sorted
to guarantee a consistent locking order, but the names were not
sorted when acquiring all locks in the set.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 4776e022
......@@ -841,8 +841,6 @@ class LockSet:
# Support passing in a single resource to acquire rather than many
if isinstance(names, basestring):
names = [names]
else:
names = sorted(names)
return self.__acquire_inner(names, False, shared,
running_timeout.Remaining, test_notify)
......@@ -891,8 +889,9 @@ class LockSet:
# First we look the locks up on __lockdict. We have no way of being sure
# they will still be there after, but this makes it a lot faster should
# just one of them be the already wrong
for lname in utils.UniqueSequence(names):
# just one of them be the already wrong. Using a sorted sequence to prevent
# deadlocks.
for lname in sorted(utils.UniqueSequence(names)):
try:
lock = self.__lockdict[lname] # raises KeyError if lock is not there
except KeyError:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment