I looked at this for awhile trying to find if there's some way we could reduce the number of leaked threads, since killing them (naked greenlet) is not always possible as evidenced by gibi's abandoned patch [1] and some similar things I have tried locally since.
I noticed that when the nova-compute service is stopped by calling stop(), the part that cleans up live migrations in the thread pool uses wait=False [2]:
def _cleanup_live_migrations_in_pool(self):
# Shutdown the pool so we don't get new requests. self._live_migration_executor.shutdown(wait=False)
which "If True then shutdown will not return until all running futures have finished executing and the resources used by the executor have been reclaimed." [3]. So wait=False will move on even while running futures are still executing.
I wondered if a patch like the following might reduce the chances of a leaked greenlet from a previous test running during a new test:
import fixtures
+import futurist
import mock
from oslo_cache import core as cache
from oslo_concurrency import lockutils
@@ -290,6 +291,15 @@ class TestCase(base.BaseTestCase):
# instead of only once initialized for test worker wsgi_app.init_global_data.reset()
I looked at this for awhile trying to find if there's some way we could reduce the number of leaked threads, since killing them (naked greenlet) is not always possible as evidenced by gibi's abandoned patch [1] and some similar things I have tried locally since.
I noticed that when the nova-compute service is stopped by calling stop(), the part that cleans up live migrations in the thread pool uses wait=False [2]:
def cleanup_host(self):
self.driver. register_ event_listener( None)
self.instance_ events. cancel_ all_events( )
self.driver. cleanup_ host(host= self.host)
self._ cleanup_ live_migrations _in_pool( )
def _cleanup_ live_migrations _in_pool( self):
self._ live_migration_ executor. shutdown( wait=False)
# Shutdown the pool so we don't get new requests.
which "If True then shutdown will not return until all running futures have finished executing and the resources used by the executor have been reclaimed." [3]. So wait=False will move on even while running futures are still executing.
I wondered if a patch like the following might reduce the chances of a leaked greenlet from a previous test running during a new test:
diff --git a/nova/test.py b/nova/test.py .69b9d06cdc 100644
index a6449c01f0.
--- a/nova/test.py
+++ b/nova/test.py
@@ -37,6 +37,7 @@ import pprint
import sys
import fixtures base.BaseTestCa se):
wsgi_ app.init_ global_ data.reset( )
+import futurist
import mock
from oslo_cache import core as cache
from oslo_concurrency import lockutils
@@ -290,6 +291,15 @@ class TestCase(
# instead of only once initialized for test worker
+ orig_shutdown = futurist. GreenThreadPool Executor. shutdown (fixtures. MonkeyPatch( GreenThreadPool Executor. shutdown' , wrap_shutdown))
+
+ def wrap_shutdown(*a, **kw):
+ kw['wait'] = True
+ return orig_shutdown(*a, **kw)
+
+ self.useFixture
+ 'futurist.
+
but I haven't been able to reproduce the failure to tell if it might help.
[1] https:/ /review. opendev. org/c/openstack /nova/+ /815017 /github. com/openstack/ nova/blob/ b8cc5704558d3c0 8fda9db2f1bb7fe cb2bcd985d/ nova/compute/ manager. py#L1627 /docs.openstack .org/futurist/ latest/ reference/ index.html# futurist. GreenThreadPool Executor. shutdown
[2] https:/
[3] https:/