summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2022-12-08 17:29:49 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-12-09 13:22:11 +0000
commita9505a86fdcd789093732b800ba08e7a23c21070 (patch)
tree9f270d04c91a63865d6e02365b8208a02fc10baf
parent8aa083f842cc54fb7c0ef3ff8724fed2dff40d66 (diff)
downloadpoky-a9505a86fdcd789093732b800ba08e7a23c21070.tar.gz
bitbake: main/server: Add lockfile debugging upon server retry
We keep seeing server issues where the lockfile is present but we can't connect to it. Reuse the lockfile debugging code from the server to dump better information to the console from the client side when we run into this issue. Whilst not pretty, this might give us a chance of being able to debug the problems further. (Bitbake rev: 22685460b5ecb1aeb4ff3436088ecdacb43044d7) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-xbitbake/lib/bb/main.py9
-rw-r--r--bitbake/lib/bb/server/process.py53
2 files changed, 37 insertions, 25 deletions
diff --git a/bitbake/lib/bb/main.py b/bitbake/lib/bb/main.py
index 6294b85cfd..1e38d04bcf 100755
--- a/bitbake/lib/bb/main.py
+++ b/bitbake/lib/bb/main.py
@@ -422,7 +422,7 @@ def setup_bitbake(configParams, extrafeatures=None):
422 retries = 8 422 retries = 8
423 while retries: 423 while retries:
424 try: 424 try:
425 topdir, lock = lockBitbake() 425 topdir, lock, lockfile = lockBitbake()
426 sockname = topdir + "/bitbake.sock" 426 sockname = topdir + "/bitbake.sock"
427 if lock: 427 if lock:
428 if configParams.status_only or configParams.kill_server: 428 if configParams.status_only or configParams.kill_server:
@@ -439,12 +439,15 @@ def setup_bitbake(configParams, extrafeatures=None):
439 logger.info("Reconnecting to bitbake server...") 439 logger.info("Reconnecting to bitbake server...")
440 if not os.path.exists(sockname): 440 if not os.path.exists(sockname):
441 logger.info("Previous bitbake instance shutting down?, waiting to retry... (%s)" % timestamp()) 441 logger.info("Previous bitbake instance shutting down?, waiting to retry... (%s)" % timestamp())
442 procs = bb.server.process.get_lockfile_process_msg(lockfile)
443 if procs:
444 logger.info("Processes holding bitbake.lock:\n%s" % procs)
442 i = 0 445 i = 0
443 lock = None 446 lock = None
444 # Wait for 5s or until we can get the lock 447 # Wait for 5s or until we can get the lock
445 while not lock and i < 50: 448 while not lock and i < 50:
446 time.sleep(0.1) 449 time.sleep(0.1)
447 _, lock = lockBitbake() 450 _, lock, _ = lockBitbake()
448 i += 1 451 i += 1
449 if lock: 452 if lock:
450 bb.utils.unlockfile(lock) 453 bb.utils.unlockfile(lock)
@@ -494,5 +497,5 @@ def lockBitbake():
494 bb.error("Unable to find conf/bblayers.conf or conf/bitbake.conf. BBPATH is unset and/or not in a build directory?") 497 bb.error("Unable to find conf/bblayers.conf or conf/bitbake.conf. BBPATH is unset and/or not in a build directory?")
495 raise BBMainFatal 498 raise BBMainFatal
496 lockfile = topdir + "/bitbake.lock" 499 lockfile = topdir + "/bitbake.lock"
497 return topdir, bb.utils.lockfile(lockfile, False, False) 500 return topdir, bb.utils.lockfile(lockfile, False, False), lockfile
498 501
diff --git a/bitbake/lib/bb/server/process.py b/bitbake/lib/bb/server/process.py
index afd77ac0a5..f4ab80ba67 100644
--- a/bitbake/lib/bb/server/process.py
+++ b/bitbake/lib/bb/server/process.py
@@ -41,6 +41,35 @@ def serverlog(msg):
41 print(str(os.getpid()) + " " + datetime.datetime.now().strftime('%H:%M:%S.%f') + " " + msg) 41 print(str(os.getpid()) + " " + datetime.datetime.now().strftime('%H:%M:%S.%f') + " " + msg)
42 sys.stdout.flush() 42 sys.stdout.flush()
43 43
44#
45# When we have lockfile issues, try and find infomation about which process is
46# using the lockfile
47#
48def get_lockfile_process_msg(lockfile):
49 # Some systems may not have lsof available
50 procs = None
51 try:
52 procs = subprocess.check_output(["lsof", '-w', lockfile], stderr=subprocess.STDOUT)
53 except subprocess.CalledProcessError:
54 # File was deleted?
55 pass
56 except OSError as e:
57 if e.errno != errno.ENOENT:
58 raise
59 if procs is None:
60 # Fall back to fuser if lsof is unavailable
61 try:
62 procs = subprocess.check_output(["fuser", '-v', lockfile], stderr=subprocess.STDOUT)
63 except subprocess.CalledProcessError:
64 # File was deleted?
65 pass
66 except OSError as e:
67 if e.errno != errno.ENOENT:
68 raise
69 if procs:
70 return procs.decode("utf-8")
71 return None
72
44class ProcessServer(): 73class ProcessServer():
45 profile_filename = "profile.log" 74 profile_filename = "profile.log"
46 profile_processed_filename = "profile.log.processed" 75 profile_processed_filename = "profile.log.processed"
@@ -306,30 +335,10 @@ class ProcessServer():
306 return 335 return
307 336
308 if not lock: 337 if not lock:
309 # Some systems may not have lsof available 338 procs = get_lockfile_process_msg(lockfile)
310 procs = None
311 try:
312 procs = subprocess.check_output(["lsof", '-w', lockfile], stderr=subprocess.STDOUT)
313 except subprocess.CalledProcessError:
314 # File was deleted?
315 continue
316 except OSError as e:
317 if e.errno != errno.ENOENT:
318 raise
319 if procs is None:
320 # Fall back to fuser if lsof is unavailable
321 try:
322 procs = subprocess.check_output(["fuser", '-v', lockfile], stderr=subprocess.STDOUT)
323 except subprocess.CalledProcessError:
324 # File was deleted?
325 continue
326 except OSError as e:
327 if e.errno != errno.ENOENT:
328 raise
329
330 msg = ["Delaying shutdown due to active processes which appear to be holding bitbake.lock"] 339 msg = ["Delaying shutdown due to active processes which appear to be holding bitbake.lock"]
331 if procs: 340 if procs:
332 msg.append(":\n%s" % str(procs.decode("utf-8"))) 341 msg.append(":\n%s" % procs)
333 serverlog("".join(msg)) 342 serverlog("".join(msg))
334 343
335 def idle_commands(self, delay, fds=None): 344 def idle_commands(self, delay, fds=None):