From bc38335d5899b0a8bf195e30e264ff01f166ec7f Mon Sep 17 00:00:00 2001 From: shihanzhang Date: Tue, 14 Jul 2015 17:32:48 +0800 Subject: [PATCH] Avoid using logging in signal handler In some cases, logging can grab locks and thusly attempt to reschedule, which will fail in signal handlers. this patch removes the actions from the signal handers, just set a flat if it got a signal, then in rpc_loop, check the flag and perform appropriate actions. Change-Id: I7a477e1c95b63fa8070ec9d08656156571421bb6 Partial-Bug: #1029727 --- .../openvswitch/agent/ovs_neutron_agent.py | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py index 4ca3423605e..0c6668d3c80 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py @@ -289,6 +289,9 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin, self.iter_num = 0 self.run_daemon_loop = True + self.catch_sigterm = False + self.catch_sighup = False + # The initialization is complete; we can start receiving messages self.connection.consume_in_threads() @@ -1477,7 +1480,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin, ancillary_ports = set() tunnel_sync = True ovs_restarted = False - while self.run_daemon_loop: + while self._check_and_handle_signal(): start = time.time() port_stats = {'regular': {'added': 0, 'updated': 0, @@ -1614,17 +1617,26 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin, self.rpc_loop(polling_manager=pm) def _handle_sigterm(self, signum, frame): - LOG.info(_LI("Agent caught SIGTERM, quitting daemon loop.")) - self.run_daemon_loop = False + self.catch_sigterm = True if self.quitting_rpc_timeout: self.set_rpc_timeout(self.quitting_rpc_timeout) def _handle_sighup(self, signum, frame): - LOG.info(_LI("Agent caught SIGHUP, resetting.")) - self.conf.reload_config_files() - config.setup_logging() - LOG.debug('Full set of CONF:') - self.conf.log_opt_values(LOG, std_logging.DEBUG) + self.catch_sighup = True + + def _check_and_handle_signal(self): + if self.catch_sigterm: + LOG.info(_LI("Agent caught SIGTERM, quitting daemon loop.")) + self.run_daemon_loop = False + self.catch_sigterm = False + if self.catch_sighup: + LOG.info(_LI("Agent caught SIGHUP, resetting.")) + self.conf.reload_config_files() + config.setup_logging() + LOG.debug('Full set of CONF:') + self.conf.log_opt_values(LOG, std_logging.DEBUG) + self.catch_sighup = False + return self.run_daemon_loop def set_rpc_timeout(self, timeout): for rpc_api in (self.plugin_rpc, self.sg_plugin_rpc,