Cleanly shutdown zuul scheduler if startup fails

At the moment, sys.exit is used to terminate the scheduler in case
an exception is thrown during startup phase. However, since not
all remaining threads were either daemonized or stopped, sys.exit
waited indefinitely. This change uses Scheduler.stop before exiting
so that all non-daemonized threads are terminated before exit.

Change-Id: I9e1a753e897276b0b0f5c1b5735d05f1cfa8f9f1
This commit is contained in:
Markus Hosch 2018-01-23 11:14:32 +01:00
parent bdcd29b8fe
commit 12c51791c2
2 changed files with 2 additions and 0 deletions

View File

@ -159,6 +159,7 @@ class Scheduler(zuul.cmd.ZuulDaemonApp):
self.log.exception("Error starting Zuul:")
# TODO(jeblair): If we had all threads marked as daemon,
# we might be able to have a nicer way of exiting here.
self.sched.stop()
sys.exit(1)
signal.signal(signal.SIGHUP, self.reconfigure_handler)

View File

@ -230,6 +230,7 @@ class Scheduler(threading.Thread):
self.statsd = get_statsd(config)
self.rpc = rpclistener.RPCListener(config, self)
self.stats_thread = threading.Thread(target=self.runStats)
self.stats_thread.daemon = True
self.stats_stop = threading.Event()
# TODO(jeblair): fix this
# Despite triggers being part of the pipeline, there is one trigger set