Skip to contentSkip to conversation

utils: Fix lockfile_to_exclusive to avoid deadlock

PATCH Superseded Richard Purdie 1 participant 1 message Aug 20

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils: Fix lockfile_to_exclusive to avoid deadlock

We need to drop the existing lock when trying to get the exclusive lock else we'd deadlock with another process trying to do the same thing.

---
 lib/bb/utils.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
lib/bb/utils.py +4 -3
index b635f68a153..37edd435350 100644
@@ -587,12 +587,13 @@ def lockfile(name, shared=False, retry=True, block=False):
         if not retry:
             return None
 
+# We have to drop the existing lock to avoid deadlocks
 def lockfile_to_exclusive(lf):
     if not lf:
         return
-    fileno = lf.fileno()
-    fcntl.flock(fileno, fcntl.LOCK_EX)
-    return
+    name = lf.name
+    unlockfile(lf)
+    return lockfile(name)
 
 def unlockfile(lf):
     """