All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] cooker: Try and avoid parseing hangs
@ 2025-07-02 22:24 Richard Purdie
  2025-07-02 22:24 ` [PATCH 2/2] cooker: Use a queue to feed parsing jobs Richard Purdie
  2025-07-03 14:07 ` [bitbake-devel] [PATCH 1/2] cooker: Try and avoid parseing hangs Joshua Watt
  0 siblings, 2 replies; 8+ messages in thread
From: Richard Purdie @ 2025-07-02 22:24 UTC (permalink / raw)
  To: bitbake-devel

We sometimes see hangs in parsing during automated testing. It appears that
SIGINT was sent to the underlying processes which see KeyboardInterrupt but
they're stuck trying to write into the results pipe. The SIGINT was probably
from some kind of parsing failure which doens't happen often, hence the hang
being rare (in the incompatible license selftests from OE).

This patch:
  * sets a flag to indicate exit upon SIGINT so the exit is more graceful
    and a defined exit path
  * empties the results queue after we send the quit event
  * empties the results queue after the SIGINT for good measure
  * increases the 0.5s timeout to 2s since we now have some very slow to
    parse recipes due to class extensions (ptests)

This should hopefully make the parsing failure codepaths more robust.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/cooker.py | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
index 1810bcc6049..91e3ee025ea 100644
--- a/lib/bb/cooker.py
+++ b/lib/bb/cooker.py
@@ -2009,6 +2009,7 @@ class Parser(multiprocessing.Process):
         self.queue_signals = False
         self.signal_received = []
         self.signal_threadlock = threading.Lock()
+        self.exit = False
 
     def catch_sig(self, signum, frame):
         if self.queue_signals:
@@ -2021,7 +2022,7 @@ class Parser(multiprocessing.Process):
             signal.signal(signal.SIGTERM, signal.SIG_DFL)
             os.kill(os.getpid(), signal.SIGTERM)
         elif signum == signal.SIGINT:
-            signal.default_int_handler(signum, frame)
+            self.exit = True
 
     def run(self):
 
@@ -2059,7 +2060,7 @@ class Parser(multiprocessing.Process):
         pending = []
         havejobs = True
         try:
-            while havejobs or pending:
+            while (havejobs or pending) and not self.exit:
                 if self.quit.is_set():
                     break
 
@@ -2196,11 +2197,12 @@ class CookerParser(object):
 
         # Cleanup the queue before call process.join(), otherwise there might be
         # deadlocks.
-        while True:
-            try:
-               self.result_queue.get(timeout=0.25)
-            except queue.Empty:
-                break
+        def read_results():
+            while True:
+                try:
+                   self.result_queue.get(timeout=0.25)
+                except queue.Empty:
+                    break
 
         def sync_caches():
             for c in self.bb_caches.values():
@@ -2212,15 +2214,19 @@ class CookerParser(object):
 
         self.parser_quit.set()
 
+        read_results()
+
         for process in self.processes:
-            process.join(0.5)
+            process.join(2)
 
         for process in self.processes:
             if process.exitcode is None:
                 os.kill(process.pid, signal.SIGINT)
 
+        read_results()
+
         for process in self.processes:
-            process.join(0.5)
+            process.join(2)
 
         for process in self.processes:
             if process.exitcode is None:


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-07-05  6:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-02 22:24 [PATCH 1/2] cooker: Try and avoid parseing hangs Richard Purdie
2025-07-02 22:24 ` [PATCH 2/2] cooker: Use a queue to feed parsing jobs Richard Purdie
2025-07-03 14:27   ` [bitbake-devel] " Joshua Watt
2025-07-03 14:30     ` Richard Purdie
2025-07-03 14:50       ` Joshua Watt
2025-07-04 21:42         ` Richard Purdie
     [not found]         ` <184F2A5B284B1D1A.1065@lists.openembedded.org>
2025-07-05  6:27           ` Richard Purdie
2025-07-03 14:07 ` [bitbake-devel] [PATCH 1/2] cooker: Try and avoid parseing hangs Joshua Watt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.