From 151e8b8e62a508f07e4a67bee2418e4965c59944 Mon Sep 17 00:00:00 2001 From: Oleksii Chuprykov Date: Fri, 25 Mar 2016 18:36:34 +0200 Subject: [PATCH] Stop engine service correctly If SIGINT received right after start of heat engine, in the middle of start() method, heat engine can not stop correctly. Clean up only those resources that actually exist. Change-Id: I496f6284e15b4f71b166cc0713cfd41423cce400 Closes-Bug: #1562042 --- heat/engine/service.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/heat/engine/service.py b/heat/engine/service.py index 8b1158e10f..9c03bc7bba 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -407,6 +407,8 @@ class EngineService(service.Service): def _stop_rpc_server(self): # Stop rpc connection at first for preventing new requests + if self._rpc_server is None: + return LOG.debug("Attempting to stop engine service...") try: self._rpc_server.stop() @@ -423,20 +425,21 @@ class EngineService(service.Service): self.worker_service.stop() # Wait for all active threads to be finished - for stack_id in list(self.thread_group_mgr.groups.keys()): - # Ignore dummy service task - if stack_id == cfg.CONF.periodic_interval: - continue - LOG.info(_LI("Waiting stack %s processing to be finished"), - stack_id) - # Stop threads gracefully - self.thread_group_mgr.stop(stack_id, True) - LOG.info(_LI("Stack %s processing was finished"), stack_id) - - self.manage_thread_grp.stop() - ctxt = context.get_admin_context() - service_objects.Service.delete(ctxt, self.service_id) - LOG.info(_LI('Service %s is deleted'), self.service_id) + if self.thread_group_mgr: + for stack_id in list(self.thread_group_mgr.groups.keys()): + # Ignore dummy service task + if stack_id == cfg.CONF.periodic_interval: + continue + LOG.info(_LI("Waiting stack %s processing to be finished"), + stack_id) + # Stop threads gracefully + self.thread_group_mgr.stop(stack_id, True) + LOG.info(_LI("Stack %s processing was finished"), stack_id) + if self.manage_thread_grp: + self.manage_thread_grp.stop() + ctxt = context.get_admin_context() + service_objects.Service.delete(ctxt, self.service_id) + LOG.info(_LI('Service %s is deleted'), self.service_id) # Terminate the engine process LOG.info(_LI("All threads were gone, terminating engine"))