diff mbox series

utils: Fix lockfile_to_exclusive to avoid deadlock

Message ID 20260820100840.2591098-1-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit f56f63b89c02adfa0289a197f8eac2ed7054ca2f
Headers show
Series utils: Fix lockfile_to_exclusive to avoid deadlock | expand

Commit Message

Richard Purdie Aug. 20, 2026, 10:08 a.m. UTC
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.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/utils.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index b635f68a153..37edd435350 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -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):
     """