diff --git a/swift/common/utils/__init__.py b/swift/common/utils/__init__.py index f1ac1ed83e..a6c263fda0 100644 --- a/swift/common/utils/__init__.py +++ b/swift/common/utils/__init__.py @@ -4853,6 +4853,14 @@ class Watchdog(object): if self._run_gth is None: self._run_gth = eventlet.spawn(self.run) + def kill(self): + """ + Stop the watchdog greenthread. + """ + if self._run_gth is not None: + self._run_gth.kill() + self._run_gth = None + def run(self): while True: self._run() diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index c9a100b637..77b0d25248 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -460,7 +460,10 @@ def run_server(conf, logger, sock, global_conf=None, ready_callback=None, except socket.error as err: if err.errno != errno.EINVAL: raise - pool.waitall() + finally: + pool.waitall() + if hasattr(app._pipeline_final_app, 'watchdog'): + app._pipeline_final_app.watchdog.kill() class StrategyBase(object): diff --git a/test/unit/common/test_wsgi.py b/test/unit/common/test_wsgi.py index 3e364c901b..73f3a22cf8 100644 --- a/test/unit/common/test_wsgi.py +++ b/test/unit/common/test_wsgi.py @@ -634,6 +634,7 @@ class TestWSGI(unittest.TestCase, ConfigAssertMixin): server_sock, server_app, server_logger = args self.assertEqual(sock, server_sock) self.assertIsInstance(server_app, swift.proxy.server.Application) + self.assertIsNone(server_app.watchdog._run_gth) self.assertEqual(20, server_app.client_timeout) self.assertIsInstance(server_logger, wsgi.NullLogger) self.assertTrue('custom_pool' in kwargs) diff --git a/test/unit/helpers.py b/test/unit/helpers.py index 2d22884cca..63ada0aa28 100644 --- a/test/unit/helpers.py +++ b/test/unit/helpers.py @@ -335,6 +335,10 @@ def setup_servers(the_object_server=object_server, extra_conf=None): def teardown_servers(context): for server in context["test_coros"]: server.kill() + # We didn't start the proxy w/ run_server, so we have to kill the + # watchdog ourselves + context["test_servers"][0].watchdog.kill() + assert context["test_servers"][0].watchdog._run_gth is None rmtree(os.path.dirname(context["testdir"])) utils.logs.SysLogHandler = context["orig_SysLogHandler"] storage_policy._POLICIES = context["orig_POLICIES"]