From fa87963b357c705597c61ffacb0f9c2ac12c1bd3 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Fri, 31 Jul 2015 10:16:33 +0100 Subject: bitbake: bitbake: cooker: properly fix bitbake.lock handling If the PR server or indeed any other child process takes some time to exit (which it sometimes does when saving its database), it can end up holding bitbake.lock after the UI exits, which led to errors if you ran bitbake commands successively - we saw this when running the PR server oe-selftest tests in OE-Core. The recent attempt to fix this wasn't quite right and ended up breaking memory resident bitbake. This time we close the lock file when cooker shuts down (inside the UI process) instead of unlocking it, and this is done in the cooker code rather than the actual UI code so it doesn't matter which UI is in use. Additionally we report that we're waiting for the lock to be released, using lsof or fuser if available to list the processes with the lock open. The 'magic' in the locking is due to all spawned subprocesses of bitbake holding an open file descriptor to the bitbake.lock. It is automatically unlocked when all those fds close the file (as all the processes terminate). We close the UI copy of the lock explicitly, then close the server process copy, any remaining open copy is therefore some proess exiting. (The reproducer for the problem is to set PRSERV_HOST = "localhost:0" and add a call to time.sleep(20) after self.server_close() in lib/prserv/serv.py, then run "bitbake -p; bitbake -p" ). Cleanup work done by Paul Eggleton . This reverts bitbake commit 69ecd15aece54753154950c55d7af42f85ad8606 and e97a9f1528d77503b5c93e48e3de9933fbb9f3cd. (Bitbake rev: a29780bd43f74b7326fe788dbd65177b86806fcf) (Bitbake rev: ed30f4ee1cef8db9ea422c5e54b2375c4f3b1d6f) Signed-off-by: Paul Eggleton Signed-off-by: Richard Purdie Conflicts: bitbake/lib/bb/tinfoil.py --- bitbake/lib/bb/cooker.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'bitbake/lib/bb/cooker.py') diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py index f32dae0f58..d9bffc3ad2 100644 --- a/bitbake/lib/bb/cooker.py +++ b/bitbake/lib/bb/cooker.py @@ -38,6 +38,8 @@ import bb, bb.exceptions, bb.command from bb import utils, data, parse, event, cache, providers, taskdata, runqueue import Queue import signal +import subprocess +import errno import prserv.serv import pyinotify @@ -1525,6 +1527,34 @@ class BBCooker: def post_serve(self): prserv.serv.auto_shutdown(self.data) bb.event.fire(CookerExit(), self.expanded_data) + lockfile = self.lock.name + self.lock.close() + self.lock = None + + while not self.lock: + with bb.utils.timeout(3): + self.lock = bb.utils.lockfile(lockfile, shared=False, retry=False, block=True) + if not self.lock: + # Some systems may not have lsof available + procs = None + try: + procs = subprocess.check_output(["lsof", '-w', lockfile], stderr=subprocess.STDOUT) + except OSError as e: + if e.errno != errno.ENOENT: + raise + if procs is None: + # Fall back to fuser if lsof is unavailable + try: + procs = subprocess.check_output(["fuser", '-v', lockfile], stderr=subprocess.STDOUT) + except OSError as e: + if e.errno != errno.ENOENT: + raise + + msg = "Delaying shutdown due to active processes which appear to be holding bitbake.lock" + if procs: + msg += ":\n%s" % str(procs) + print(msg) + def shutdown(self, force = False): if force: -- cgit v1.2.3-54-g00ecf