[3/3] server/process: Remove daemonic thread usage

Message ID 20220607141735.341158-3-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit f5ad8349a5dbff9824a89f5708cfd011d61888c9
Headers show
Series [1/3] fetch/wget: Move files into place atomically | expand

Commit Message

Richard Purdie June 7, 2022, 2:17 p.m. UTC
We're seeing UI deadlocks occasionally and this is possibly due to the
use of a daemonic thread in the UI event queue processing. This thread
could terminate holding a threading Lock() which would cause issues
for the process when exitting.

Change the shutdown process to handle this more cleanly.

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

Patch

diff --git a/lib/bb/server/process.py b/lib/bb/server/process.py
index 74b74dc39b..b330520a98 100644
--- a/lib/bb/server/process.py
+++ b/lib/bb/server/process.py
@@ -437,6 +437,7 @@  class BitBakeProcessServerConnection(object):
         self.socket_connection = sock
 
     def terminate(self):
+        self.events.close()
         self.socket_connection.close()
         self.connection.connection.close()
         self.connection.recv.close()
@@ -662,7 +663,6 @@  class BBUIEventQueue:
         self.reader = ConnectionReader(readfd)
 
         self.t = threading.Thread()
-        self.t.daemon = True
         self.t.run = self.startCallbackHandler
         self.t.start()
 
@@ -693,13 +693,16 @@  class BBUIEventQueue:
         bb.utils.set_process_name("UIEventQueue")
         while True:
             try:
-                self.reader.wait()
+                self.reader.wait(0.25)
                 event = self.reader.get()
                 self.queue_event(event)
-            except EOFError:
+            except (EOFError, OSError):
                 # Easiest way to exit is to close the file descriptor to cause an exit
                 break
+
+    def close(self):
         self.reader.close()
+        self.t.join()
 
 class ConnectionReader(object):