From bbc5af116686a25a942fd0f70c09a69271f43c84 Mon Sep 17 00:00:00 2001 From: Slawek Kaplonski Date: Thu, 13 Jan 2022 09:04:10 +0100 Subject: [PATCH] Register cleanup hooks for the object change handlers only when needed In patch [1] there was added threads for the object change handlers and this patch also added cleanup method which was registered to be linked with the SIGINT, SIGTERM and run "atexit" to clean all object change handler threads. But that cleanup was linked with those signals always when neutron.plugins.ml2.ovo_rpc module was imported and that can cause e.g. some errors in the functional tests (we saw them only in the stable/train branch so far but maybe it can happen also in other branches). To avoid that, this patch links cleanup with those signals only when object change handler threads are really started. Related-Bug: #1926417 [1] https://review.opendev.org/c/openstack/neutron/+/788510 Change-Id: I40b72316bd0f4281484d3cf07542177297028e34 --- neutron/plugins/ml2/ovo_rpc.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/neutron/plugins/ml2/ovo_rpc.py b/neutron/plugins/ml2/ovo_rpc.py index 515ba8e32f4..7c1e755981e 100644 --- a/neutron/plugins/ml2/ovo_rpc.py +++ b/neutron/plugins/ml2/ovo_rpc.py @@ -36,6 +36,12 @@ from neutron.objects import subnet LOG = logging.getLogger(__name__) +def _setup_change_handlers_cleanup(): + atexit.register(_ObjectChangeHandler.clean_up) + signal.signal(signal.SIGINT, _ObjectChangeHandler.clean_up) + signal.signal(signal.SIGTERM, _ObjectChangeHandler.clean_up) + + class _ObjectChangeHandler(object): MAX_IDLE_FOR = 1 _TO_CLEAN = weakref.WeakSet() @@ -151,6 +157,7 @@ class OVOServerRpcInterface(object): def __init__(self): self._rpc_pusher = resources_rpc.ResourcesPushRpcApi() self._setup_change_handlers() + _setup_change_handlers_cleanup() LOG.debug("ML2 OVO RPC backend initialized.") def _setup_change_handlers(self): @@ -172,8 +179,3 @@ class OVOServerRpcInterface(object): """Wait for all handlers to finish processing async events.""" for handler in self._resource_handlers.values(): handler.wait() - - -atexit.register(_ObjectChangeHandler.clean_up) -signal.signal(signal.SIGINT, _ObjectChangeHandler.clean_up) -signal.signal(signal.SIGTERM, _ObjectChangeHandler.clean_up)