summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/server
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2023-01-04 12:32:35 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-01-05 11:50:17 +0000
commita19687acd12497d727203e63d74b2703387f34a6 (patch)
tree813515cdfb0c807435db26acb6bafc2d351f48f1 /bitbake/lib/bb/server
parent2c6f0b9228b47459dd1b67d578792cd017006128 (diff)
downloadpoky-a19687acd12497d727203e63d74b2703387f34a6.tar.gz
bitbake: lib/bb: Update thread/process locks to use a timeout
The thread/process locks we use translate to futexes in Linux. If a process dies holding the lock, anything else trying to take the lock will hang indefinitely. An example would be the OOM killer taking out a parser process. To avoid bitbake processes just hanging indefinitely, add a timeout to our lock calls using a context manager. If we can't obtain the lock after waiting 5 minutes, hard exit out using os._exit(1). Use _exit() to avoid locking in any other places trying to write error messages to event handler queues (which also need locks). Whilst a bit harsh, this should mean we stop having lots of long running processes in cases where things are never going to work out and also avoids hanging builds on the autobuilder. (Bitbake rev: d2a3f662b0eed900fc012a392bfa0a365df0df9b) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/server')
-rw-r--r--bitbake/lib/bb/server/process.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/bitbake/lib/bb/server/process.py b/bitbake/lib/bb/server/process.py
index ac7749d36c..b5f6faf6fb 100644
--- a/bitbake/lib/bb/server/process.py
+++ b/bitbake/lib/bb/server/process.py
@@ -113,7 +113,7 @@ class ProcessServer():
113 def register_idle_function(self, function, data): 113 def register_idle_function(self, function, data):
114 """Register a function to be called while the server is idle""" 114 """Register a function to be called while the server is idle"""
115 assert hasattr(function, '__call__') 115 assert hasattr(function, '__call__')
116 with self._idlefuncsLock: 116 with bb.utils.lock_timeout(self._idlefuncsLock):
117 self._idlefuns[function] = data 117 self._idlefuns[function] = data
118 serverlog("Registering idle function %s" % str(function)) 118 serverlog("Registering idle function %s" % str(function))
119 119
@@ -379,7 +379,7 @@ class ProcessServer():
379 379
380 def idle_thread(self): 380 def idle_thread(self):
381 def remove_idle_func(function): 381 def remove_idle_func(function):
382 with self._idlefuncsLock: 382 with bb.utils.lock_timeout(self._idlefuncsLock):
383 del self._idlefuns[function] 383 del self._idlefuns[function]
384 self.idle_cond.notify_all() 384 self.idle_cond.notify_all()
385 385
@@ -387,7 +387,7 @@ class ProcessServer():
387 nextsleep = 0.1 387 nextsleep = 0.1
388 fds = [] 388 fds = []
389 389
390 with self._idlefuncsLock: 390 with bb.utils.lock_timeout(self._idlefuncsLock):
391 items = list(self._idlefuns.items()) 391 items = list(self._idlefuns.items())
392 392
393 for function, data in items: 393 for function, data in items:
@@ -743,7 +743,7 @@ class BBUIEventQueue:
743 self.t.start() 743 self.t.start()
744 744
745 def getEvent(self): 745 def getEvent(self):
746 with self.eventQueueLock: 746 with bb.utils.lock_timeout(self.eventQueueLock):
747 if len(self.eventQueue) == 0: 747 if len(self.eventQueue) == 0:
748 return None 748 return None
749 749
@@ -758,7 +758,7 @@ class BBUIEventQueue:
758 return self.getEvent() 758 return self.getEvent()
759 759
760 def queue_event(self, event): 760 def queue_event(self, event):
761 with self.eventQueueLock: 761 with bb.utils.lock_timeout(self.eventQueueLock):
762 self.eventQueue.append(event) 762 self.eventQueue.append(event)
763 self.eventQueueNotify.set() 763 self.eventQueueNotify.set()
764 764
@@ -794,7 +794,7 @@ class ConnectionReader(object):
794 return self.reader.poll(timeout) 794 return self.reader.poll(timeout)
795 795
796 def get(self): 796 def get(self):
797 with self.rlock: 797 with bb.utils.lock_timeout(self.rlock):
798 res = self.reader.recv_bytes() 798 res = self.reader.recv_bytes()
799 return multiprocessing.reduction.ForkingPickler.loads(res) 799 return multiprocessing.reduction.ForkingPickler.loads(res)
800 800
@@ -815,7 +815,7 @@ class ConnectionWriter(object):
815 815
816 def _send(self, obj): 816 def _send(self, obj):
817 gc.disable() 817 gc.disable()
818 with self.wlock: 818 with bb.utils.lock_timeout(self.wlock):
819 self.writer.send_bytes(obj) 819 self.writer.send_bytes(obj)
820 gc.enable() 820 gc.enable()
821 821
@@ -828,7 +828,7 @@ class ConnectionWriter(object):
828 # pthread_sigmask block/unblock would be nice but doesn't work, https://bugs.python.org/issue47139 828 # pthread_sigmask block/unblock would be nice but doesn't work, https://bugs.python.org/issue47139
829 process = multiprocessing.current_process() 829 process = multiprocessing.current_process()
830 if process and hasattr(process, "queue_signals"): 830 if process and hasattr(process, "queue_signals"):
831 with process.signal_threadlock: 831 with bb.utils.lock_timeout(process.signal_threadlock):
832 process.queue_signals = True 832 process.queue_signals = True
833 self._send(obj) 833 self._send(obj)
834 process.queue_signals = False 834 process.queue_signals = False