summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2022-03-29 15:18:01 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-03-30 13:05:03 +0100
commit4a5a2e67a841cf0c5d798c7b7b798e0a1f1d0944 (patch)
tree72d0b668d5c6322df282346ee8d93e8e735828de
parent928bcb10a46939eaf801bea0b633e4624b5b5dfa (diff)
downloadpoky-4a5a2e67a841cf0c5d798c7b7b798e0a1f1d0944.tar.gz
bitbake: cooker: Rework force parser shutdown
The "force" option to parser shutdown was often the cause of lockups and there is no good reason we should have two different behaviours. Change and unify the codepaths to always: * Wait for longer for a controlled shutdown of a process (0.5s). Usually it will be much faster if it has finished so the delay doesn't really matter. * Send processes a SIGINT * Failing that, send a SIGTERM * Call .close() if available to release zombies This means we no longer need the "force" parameter to the function so it is removed. (Bitbake rev: de88c62ef873e9fce78ba162f5311d846de96f2b) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/bb/cooker.py37
1 files changed, 25 insertions, 12 deletions
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index 7c0c5d4efa..f435b18c87 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -1613,7 +1613,7 @@ class BBCooker:
1613 1613
1614 if self.state in (state.shutdown, state.forceshutdown, state.error): 1614 if self.state in (state.shutdown, state.forceshutdown, state.error):
1615 if hasattr(self.parser, 'shutdown'): 1615 if hasattr(self.parser, 'shutdown'):
1616 self.parser.shutdown(clean=False, force = True) 1616 self.parser.shutdown(clean=False)
1617 self.parser.final_cleanup() 1617 self.parser.final_cleanup()
1618 raise bb.BBHandledException() 1618 raise bb.BBHandledException()
1619 1619
@@ -1741,7 +1741,7 @@ class BBCooker:
1741 self.state = state.shutdown 1741 self.state = state.shutdown
1742 1742
1743 if self.parser: 1743 if self.parser:
1744 self.parser.shutdown(clean=not force, force=force) 1744 self.parser.shutdown(clean=not force)
1745 self.parser.final_cleanup() 1745 self.parser.final_cleanup()
1746 1746
1747 def finishcommand(self): 1747 def finishcommand(self):
@@ -2186,7 +2186,7 @@ class CookerParser(object):
2186 2186
2187 self.results = itertools.chain(self.results, self.parse_generator()) 2187 self.results = itertools.chain(self.results, self.parse_generator())
2188 2188
2189 def shutdown(self, clean=True, force=False): 2189 def shutdown(self, clean=True):
2190 if not self.toparse: 2190 if not self.toparse:
2191 return 2191 return
2192 if self.haveshutdown: 2192 if self.haveshutdown:
@@ -2215,11 +2215,24 @@ class CookerParser(object):
2215 break 2215 break
2216 2216
2217 for process in self.processes: 2217 for process in self.processes:
2218 if force: 2218 process.join(0.5)
2219 process.join(.1) 2219
2220 for process in self.processes:
2221 if process.exitcode is None:
2222 os.kill(process.pid, signal.SIGINT)
2223
2224 for process in self.processes:
2225 process.join(0.5)
2226
2227 for process in self.processes:
2228 if process.exitcode is None:
2220 process.terminate() 2229 process.terminate()
2221 else: 2230
2222 process.join() 2231 for process in self.processes:
2232 process.join()
2233 # Added in 3.7, cleans up zombies
2234 if hasattr(process, "close"):
2235 process.close()
2223 2236
2224 self.parser_quit.close() 2237 self.parser_quit.close()
2225 # Allow data left in the cancel queue to be discarded 2238 # Allow data left in the cancel queue to be discarded
@@ -2296,18 +2309,18 @@ class CookerParser(object):
2296 except bb.BBHandledException as exc: 2309 except bb.BBHandledException as exc:
2297 self.error += 1 2310 self.error += 1
2298 logger.debug('Failed to parse recipe: %s' % exc.recipe) 2311 logger.debug('Failed to parse recipe: %s' % exc.recipe)
2299 self.shutdown(clean=False, force=True) 2312 self.shutdown(clean=False)
2300 return False 2313 return False
2301 except ParsingFailure as exc: 2314 except ParsingFailure as exc:
2302 self.error += 1 2315 self.error += 1
2303 logger.error('Unable to parse %s: %s' % 2316 logger.error('Unable to parse %s: %s' %
2304 (exc.recipe, bb.exceptions.to_string(exc.realexception))) 2317 (exc.recipe, bb.exceptions.to_string(exc.realexception)))
2305 self.shutdown(clean=False, force=True) 2318 self.shutdown(clean=False)
2306 return False 2319 return False
2307 except bb.parse.ParseError as exc: 2320 except bb.parse.ParseError as exc:
2308 self.error += 1 2321 self.error += 1
2309 logger.error(str(exc)) 2322 logger.error(str(exc))
2310 self.shutdown(clean=False, force=True) 2323 self.shutdown(clean=False)
2311 return False 2324 return False
2312 except bb.data_smart.ExpansionError as exc: 2325 except bb.data_smart.ExpansionError as exc:
2313 self.error += 1 2326 self.error += 1
@@ -2316,7 +2329,7 @@ class CookerParser(object):
2316 tb = list(itertools.dropwhile(lambda e: e.filename.startswith(bbdir), exc.traceback)) 2329 tb = list(itertools.dropwhile(lambda e: e.filename.startswith(bbdir), exc.traceback))
2317 logger.error('ExpansionError during parsing %s', value.recipe, 2330 logger.error('ExpansionError during parsing %s', value.recipe,
2318 exc_info=(etype, value, tb)) 2331 exc_info=(etype, value, tb))
2319 self.shutdown(clean=False, force=True) 2332 self.shutdown(clean=False)
2320 return False 2333 return False
2321 except Exception as exc: 2334 except Exception as exc:
2322 self.error += 1 2335 self.error += 1
@@ -2328,7 +2341,7 @@ class CookerParser(object):
2328 # Most likely, an exception occurred during raising an exception 2341 # Most likely, an exception occurred during raising an exception
2329 import traceback 2342 import traceback
2330 logger.error('Exception during parse: %s' % traceback.format_exc()) 2343 logger.error('Exception during parse: %s' % traceback.format_exc())
2331 self.shutdown(clean=False, force=True) 2344 self.shutdown(clean=False)
2332 return False 2345 return False
2333 2346
2334 self.current += 1 2347 self.current += 1