Fuchsia: Send thread kill signal to system logging thread on error.

The runner script will hang if the script is aborted or if an error
occurs during the package copy process, because the system logging
thread will continue to stay alive.

This CL sends an event to the logging thread in the "finally"
block to request that the thread terminate.

Bug: 841458

Change-Id: Ia5073b86b8d83b576ed67c6ca6dc22ffece4f9c3
Reviewed-on: https://chromium-review.googlesource.com/1052671
Reviewed-by: Scott Graham <scottmg@chromium.org>
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#557367}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 6ec5d217f6fb600a098dfad9124614ea9c06147a
This commit is contained in:
Kevin Marshall 2018-05-09 23:05:35 +00:00 коммит произвёл Commit Bot
Родитель 9cfcd1cf68
Коммит 1bdeddd932
1 изменённых файлов: 9 добавлений и 5 удалений

Просмотреть файл

@ -22,6 +22,9 @@ from symbolizer import FilterStream
FAR = os.path.join(common.SDK_ROOT, 'tools', 'far')
PM = os.path.join(common.SDK_ROOT, 'tools', 'pm')
# Amount of time to wait for the termination of the system log output thread.
_JOIN_TIMEOUT_SECS = 5
def _AttachKernelLogReader(target):
"""Attaches a kernel log reader as a long-running SSH task."""
@ -100,9 +103,7 @@ def RunPackage(output_dir, target, package_path, package_name, run_args,
system_logger = _AttachKernelLogReader(target) if system_logging else None
package_copied = False
log_output_thread = None
try:
log_output_thread = None
if system_logger:
# Spin up a thread to asynchronously dump the system log to stdout
# for easier diagnoses of early, pre-execution failures.
@ -110,6 +111,7 @@ def RunPackage(output_dir, target, package_path, package_name, run_args,
log_output_thread = threading.Thread(
target=lambda: DrainStreamToStdout(system_logger.stdout,
log_output_quit_event))
log_output_thread.daemon = True
log_output_thread.start()
logging.info('Copying package to target.')
@ -128,9 +130,9 @@ def RunPackage(output_dir, target, package_path, package_name, run_args,
if len(output) != 1 or 'ErrAlreadyExists' not in output[0]:
raise Exception('Error while installing: %s' % '\n'.join(output))
if log_output_thread:
if system_logger:
log_output_quit_event.set()
log_output_thread.join()
log_output_thread.join(timeout=_JOIN_TIMEOUT_SECS)
logging.info('Running application.')
command = ['run', package_name] + run_args
@ -166,7 +168,9 @@ def RunPackage(output_dir, target, package_path, package_name, run_args,
finally:
if system_logger:
print 'Terminating kernel log reader.'
logging.info('Terminating kernel log reader.')
log_output_quit_event.set()
log_output_thread.join()
system_logger.kill()
if package_copied: