summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2019-07-31 10:49:39 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-08-06 11:21:32 +0100
commit43d37a6eaf2224c0dda1d1436a0afc2bd34fdddf (patch)
tree273e6a02584e2222a4f2b7249018dbd487e818e4 /bitbake
parentd40d7e43856f176c45cf515644b5f211c708e237 (diff)
downloadpoky-43d37a6eaf2224c0dda1d1436a0afc2bd34fdddf.tar.gz
bitbake: hashserv: Switch from threads to multiprocessing
There were hard to debug lockups when trying to use threading to start hashserv as a thread. Switch to multiprocessing which doesn't show the same locking problems. (Bitbake rev: be23d887c8e244f1ef961298fbc9214d0fd0968a) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/cooker.py20
-rw-r--r--bitbake/lib/hashserv/__init__.py14
-rw-r--r--bitbake/lib/hashserv/tests.py8
3 files changed, 27 insertions, 15 deletions
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index 84f25ec94e..6e1d59bb3a 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -193,6 +193,8 @@ class BBCooker:
193 bb.parse.BBHandler.cached_statements = {} 193 bb.parse.BBHandler.cached_statements = {}
194 194
195 self.ui_cmdline = None 195 self.ui_cmdline = None
196 self.hashserv = None
197 self.hashservport = None
196 198
197 self.initConfigurationData() 199 self.initConfigurationData()
198 200
@@ -231,8 +233,6 @@ class BBCooker:
231 self.state = state.initial 233 self.state = state.initial
232 234
233 self.parser = None 235 self.parser = None
234 self.hashserv = None
235 self.hashservport = None
236 236
237 signal.signal(signal.SIGTERM, self.sigterm_exception) 237 signal.signal(signal.SIGTERM, self.sigterm_exception)
238 # Let SIGHUP exit as SIGTERM 238 # Let SIGHUP exit as SIGTERM
@@ -372,12 +372,13 @@ class BBCooker:
372 self.data.setVar('BB_CMDLINE', self.ui_cmdline) 372 self.data.setVar('BB_CMDLINE', self.ui_cmdline)
373 373
374 if self.data.getVar("BB_HASHSERVE") == "localhost:0": 374 if self.data.getVar("BB_HASHSERVE") == "localhost:0":
375 dbfile = (self.data.getVar("PERSISTENT_DIR") or self.data.getVar("CACHE")) + "/hashserv.db" 375 if not self.hashserv:
376 self.hashserv = hashserv.create_server(('localhost', 0), dbfile, '') 376 dbfile = (self.data.getVar("PERSISTENT_DIR") or self.data.getVar("CACHE")) + "/hashserv.db"
377 self.hashservport = "localhost:" + str(self.hashserv.server_port) 377 self.hashserv = hashserv.create_server(('localhost', 0), dbfile, '')
378 thread = threading.Thread(target=self.hashserv.serve_forever) 378 self.hashservport = "localhost:" + str(self.hashserv.server_port)
379 thread.daemon = True 379 self.hashserv.process = multiprocessing.Process(target=self.hashserv.serve_forever)
380 thread.start() 380 self.hashserv.process.daemon = True
381 self.hashserv.process.start()
381 self.data.setVar("BB_HASHSERVE", self.hashservport) 382 self.data.setVar("BB_HASHSERVE", self.hashservport)
382 383
383 # 384 #
@@ -1658,7 +1659,8 @@ class BBCooker:
1658 def post_serve(self): 1659 def post_serve(self):
1659 prserv.serv.auto_shutdown() 1660 prserv.serv.auto_shutdown()
1660 if self.hashserv: 1661 if self.hashserv:
1661 self.hashserv.shutdown() 1662 self.hashserv.process.terminate()
1663 self.hashserv.process.join()
1662 bb.event.fire(CookerExit(), self.data) 1664 bb.event.fire(CookerExit(), self.data)
1663 1665
1664 def shutdown(self, force = False): 1666 def shutdown(self, force = False):
diff --git a/bitbake/lib/hashserv/__init__.py b/bitbake/lib/hashserv/__init__.py
index 86aa7e9de6..1d5e08ee5a 100644
--- a/bitbake/lib/hashserv/__init__.py
+++ b/bitbake/lib/hashserv/__init__.py
@@ -13,6 +13,7 @@ import logging
13import socketserver 13import socketserver
14import queue 14import queue
15import threading 15import threading
16import signal
16from datetime import datetime 17from datetime import datetime
17 18
18logger = logging.getLogger('hashserv') 19logger = logging.getLogger('hashserv')
@@ -147,8 +148,14 @@ class ThreadedHTTPServer(HTTPServer):
147 self.handlerthread.daemon = False 148 self.handlerthread.daemon = False
148 149
149 self.handlerthread.start() 150 self.handlerthread.start()
151
152 signal.signal(signal.SIGTERM, self.sigterm_exception)
150 super().serve_forever() 153 super().serve_forever()
151 154
155 def sigterm_exception(self, signum, stackframe):
156 self.server_close()
157 os._exit(0)
158
152 def process_request_thread(self): 159 def process_request_thread(self):
153 while not self.quit: 160 while not self.quit:
154 try: 161 try:
@@ -163,6 +170,7 @@ class ThreadedHTTPServer(HTTPServer):
163 self.handle_error(request, client_address) 170 self.handle_error(request, client_address)
164 finally: 171 finally:
165 self.shutdown_request(request) 172 self.shutdown_request(request)
173 os._exit(0)
166 174
167 def process_request(self, request, client_address): 175 def process_request(self, request, client_address):
168 self.requestqueue.put((request, client_address)) 176 self.requestqueue.put((request, client_address))
@@ -208,6 +216,8 @@ def create_server(addr, dbname, prefix=''):
208 cursor.execute('CREATE INDEX IF NOT EXISTS taskhash_lookup ON tasks_v2 (method, taskhash)') 216 cursor.execute('CREATE INDEX IF NOT EXISTS taskhash_lookup ON tasks_v2 (method, taskhash)')
209 cursor.execute('CREATE INDEX IF NOT EXISTS outhash_lookup ON tasks_v2 (method, outhash)') 217 cursor.execute('CREATE INDEX IF NOT EXISTS outhash_lookup ON tasks_v2 (method, outhash)')
210 218
211 logger.info('Starting server on %s', addr) 219 ret = ThreadedHTTPServer(addr, Handler)
220
221 logger.info('Starting server on %s\n', ret.server_port)
212 222
213 return ThreadedHTTPServer(addr, Handler) 223 return ret
diff --git a/bitbake/lib/hashserv/tests.py b/bitbake/lib/hashserv/tests.py
index 15f4a52ee9..6845b53884 100644
--- a/bitbake/lib/hashserv/tests.py
+++ b/bitbake/lib/hashserv/tests.py
@@ -6,7 +6,7 @@
6# 6#
7 7
8import unittest 8import unittest
9import threading 9import multiprocessing
10import sqlite3 10import sqlite3
11import hashlib 11import hashlib
12import urllib.request 12import urllib.request
@@ -21,16 +21,16 @@ class TestHashEquivalenceServer(unittest.TestCase):
21 self.dbfile = tempfile.NamedTemporaryFile(prefix="bb-hashserv-db-") 21 self.dbfile = tempfile.NamedTemporaryFile(prefix="bb-hashserv-db-")
22 self.server = create_server(('localhost', 0), self.dbfile.name) 22 self.server = create_server(('localhost', 0), self.dbfile.name)
23 self.server_addr = 'http://localhost:%d' % self.server.socket.getsockname()[1] 23 self.server_addr = 'http://localhost:%d' % self.server.socket.getsockname()[1]
24 self.server_thread = threading.Thread(target=self.server.serve_forever) 24 self.server_thread = multiprocessing.Process(target=self.server.serve_forever)
25 self.server_thread.daemon = True
25 self.server_thread.start() 26 self.server_thread.start()
26 27
27 def tearDown(self): 28 def tearDown(self):
28 # Shutdown server 29 # Shutdown server
29 s = getattr(self, 'server', None) 30 s = getattr(self, 'server', None)
30 if s is not None: 31 if s is not None:
31 self.server.shutdown() 32 self.server_thread.terminate()
32 self.server_thread.join() 33 self.server_thread.join()
33 self.server.server_close()
34 34
35 def send_get(self, path): 35 def send_get(self, path):
36 url = '%s/%s' % (self.server_addr, path) 36 url = '%s/%s' % (self.server_addr, path)