summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/server
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2022-03-29 15:17:10 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-03-30 13:05:03 +0100
commit928bcb10a46939eaf801bea0b633e4624b5b5dfa (patch)
tree42f3bc730e5fd7f4306d7b090574e30343c85cee /bitbake/lib/bb/server
parentc0ff6c75eedea6e0f472b45456aed238073ac157 (diff)
downloadpoky-928bcb10a46939eaf801bea0b633e4624b5b5dfa.tar.gz
bitbake: cooker/process: Fix signal handling lockups
If a parser process is terminated while holding a write lock, then it will lead to a deadlock (see https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Process.terminate). With SIGTERM, we don't want to terminate holding the lock. We also don't want a SIGINT to cause a partial write to the event stream. I tried using signal masks to avoid this but it doesn't work, see https://bugs.python.org/issue47139 Instead, add a signal handler and catch the calls around the critical section. We also need a thread lock to ensure other threads in the same process don't handle the signal until all the threads are not in the lock. (Bitbake rev: a40efaa5556a188dfe46c8d060adde37dc400dcd) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/server')
-rw-r--r--bitbake/lib/bb/server/process.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/bitbake/lib/bb/server/process.py b/bitbake/lib/bb/server/process.py
index 7c587a9110..ce53fdc678 100644
--- a/bitbake/lib/bb/server/process.py
+++ b/bitbake/lib/bb/server/process.py
@@ -20,6 +20,7 @@ import os
20import sys 20import sys
21import time 21import time
22import select 22import select
23import signal
23import socket 24import socket
24import subprocess 25import subprocess
25import errno 26import errno
@@ -737,11 +738,28 @@ class ConnectionWriter(object):
737 # Why bb.event needs this I have no idea 738 # Why bb.event needs this I have no idea
738 self.event = self 739 self.event = self
739 740
740 def send(self, obj): 741 def _send(self, obj):
741 obj = multiprocessing.reduction.ForkingPickler.dumps(obj)
742 with self.wlock: 742 with self.wlock:
743 self.writer.send_bytes(obj) 743 self.writer.send_bytes(obj)
744 744
745 def send(self, obj):
746 obj = multiprocessing.reduction.ForkingPickler.dumps(obj)
747 # See notes/code in CookerParser
748 # We must not terminate holding this lock else processes will hang.
749 # For SIGTERM, raising afterwards avoids this.
750 # For SIGINT, we don't want to have written partial data to the pipe.
751 # pthread_sigmask block/unblock would be nice but doesn't work, https://bugs.python.org/issue47139
752 process = multiprocessing.current_process()
753 if process and hasattr(process, "queue_signals"):
754 with process.signal_threadlock:
755 process.queue_signals = True
756 self._send(obj)
757 process.queue_signals = False
758 for sig in process.signal_received.pop():
759 process.handle_sig(sig, None)
760 else:
761 self._send(obj)
762
745 def fileno(self): 763 def fileno(self):
746 return self.writer.fileno() 764 return self.writer.fileno()
747 765