Skip to contentSkip to conversation

server/process: Improve lockfile handling at exit

PATCH New Richard Purdie 1 participant 1 message Jan 14, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 server/process: Improve lockfile handling at exit

If memory resident bitbake is active and the build directory is renamed upon build completion, several bad things can happen:

* the old build directory could be re-created to contain a lockfile leaving an empty directory behind
* a lockfile for a new build could be found and attempt to be locked

This patch avoids creating an empty directory (not perfectly, but should work in the majority of cases - an empty directory is cosmetic).

It also now compares the lock file contents to it's own pid and just exits if it doesn't match, it is clearly then belonging to some new process.

This will be combined with bitbake shutdown calls on the autobuilder to ensure "saved" build directories, or build directories being deleted by clobberdir don't do strange things.

---
 lib/bb/server/process.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
lib/bb/server/process.py +5 -4
index 588a3ae04d..4bd68b1e7f 100644
@@ -362,20 +362,21 @@ class ProcessServer():
             except FileNotFoundError:
                 return None
 
-        lockcontents = get_lock_contents(lockfile)
-        serverlog("Original lockfile contents: " + str(lockcontents))
-
         lock.close()
         lock = None
 
         while not lock:
             i = 0
             lock = None
+            if not os.path.exists(os.path.basename(lockfile)):
+                serverlog("Lockfile directory gone, exiting.")
+                return
+
             while not lock and i < 30:
                 lock = bb.utils.lockfile(lockfile, shared=False, retry=False, block=False)
                 if not lock:
                     newlockcontents = get_lock_contents(lockfile)
-                    if newlockcontents != lockcontents:
+                    if not newlockcontents.startswith([os.getpid() + "\n", os.getpid() + " "]):
                         # A new server was started, the lockfile contents changed, we can exit
                         serverlog("Lockfile now contains different contents, exiting: " + str(newlockcontents))
                         return
Signature · 1 line
2.37.2