Skip to contentSkip to conversation

server/process: Fix lock owner prefix check during shutdown

PATCH In review Reda Maher 2 participants 2 messages Sep 30 – Oct 15

lore
Share & tools
lore

Reda Maher

author
#0 lore raw

PATCH 1/1 server/process: Fix lock owner prefix check during shutdown

Pass a tuple to str.startswith() when checking a contended lock during shutdown. The list raises TypeError before the server can retry its own lock or recognize a replacement server.

Add a deterministic shutdown regression test covering PID-only and XML-RPC lock records, including a replacement PID sharing the old PID's prefix. Verified failure before the fix and success with bitbake-selftest bb.tests.server afterwards.

AI-Generated: Uses GitHub Copilot

---
 bin/bitbake-selftest     |  1 +
 lib/bb/server/process.py |  2 +-
 lib/bb/tests/server.py   | 57 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100644 lib/bb/tests/server.py
bin/bitbake-selftest +1 -0
index 855abb1f0..e5a68ba1d 100755
@@ -35,6 +35,7 @@ tests = ["bb.tests.codeparser",
          "bb.tests.fetch_import",
          "bb.tests.parse",
          "bb.tests.runqueue",
+         "bb.tests.server",
          "bb.tests.setup",
          "bb.tests.siggen",
          "bb.tests.utils",
lib/bb/server/process.py +1 -1
index d0f73590c..a103b0987 100644
@@ -377,7 +377,7 @@ class ProcessServer():
                 lock = bb.utils.lockfile(lockfile, shared=False, retry=False, block=False)
                 if not lock:
                     newlockcontents = get_lock_contents(lockfile)
-                    if not newlockcontents[0].startswith([f"{os.getpid()}\n", f"{os.getpid()} "]):
+                    if not newlockcontents[0].startswith((f"{os.getpid()}\n", f"{os.getpid()} ")):
                         # A new server was started, the lockfile contents changed, we can exit
                         serverlog("Lockfile now contains different contents, exiting: " + str(newlockcontents))
                         return
lib/bb/tests/server.py new file +57 -0

57 lines not on this page · raw message

Signature · 1 line
2.53.0
#1 lore raw

Hi Reda,

Quoted 1 line · Reda Maher via lists.openembedded.org

Pass a tuple to str.startswith() when checking a contended lock during shutdown. The list raises TypeError before the server can retry its own lock or recognize a replacement server.

<snip>

lib/bb/server/process.py class ProcessServer(): · line 383

Quoted 13 lines
lib/bb/server/process.py +1 -1
index d0f73590c..a103b0987 100644
@@ -377,7 +377,7 @@ class ProcessServer():
                 lock = bb.utils.lockfile(lockfile, shared=False, retry=False, block=False)
                 if not lock:
                     newlockcontents = get_lock_contents(lockfile)
-                    if not newlockcontents[0].startswith([f"{os.getpid()}\n", f"{os.getpid()} "]):
+                    if not newlockcontents[0].startswith((f"{os.getpid()}\n", f"{os.getpid()} ")):
                         # A new server was started, the lockfile contents changed, we can exit
                         serverlog("Lockfile now contains different contents, exiting: " + str(newlockcontents))
                         return

Would it also be worth handling the situation where the lockfile is missing or empty, here? By checking if not newlockcontents itself, too?

I think there may be edge cases where the lock is gone or empty and at exit this will also throw the traceback instead of a clean exit. When using the profiler this can induce a loss of some profiling data as the profiler appears to only write out its data on a clean exit.

If you add handling the missing/empty lockfile check, it may also be good to add such tests to your testing implementation.

Thanks,
Andrew