From 746d928a875281a7154dcd438f46a58bbf656db9 Mon Sep 17 00:00:00 2001 From: Dmitriy Ukhlov Date: Fri, 8 Apr 2016 16:00:16 +0300 Subject: [PATCH] Adds eventlet monkey patching of select module if thread is pathed Oslo.messaging pika driver requires patching of select module if thread is patched. Pika driver uses select call and if it is not patched onsuming messages blocks whole eventlet loop Closes-Bug: #1570242 Change-Id: I9756737309f401ebddb7475eb84725f65bca01bf --- swift/common/wsgi.py | 8 ++++++-- swift/container/updater.py | 5 +++-- swift/obj/updater.py | 3 ++- test/unit/common/test_wsgi.py | 3 +++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index 7ba97eefce..2c169eb2a6 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -407,8 +407,12 @@ def run_server(conf, logger, sock, global_conf=None): wsgi.WRITE_TIMEOUT = int(conf.get('client_timeout') or 60) eventlet.hubs.use_hub(get_hub()) - # NOTE(sileht): monkey-patching thread is required by python-keystoneclient - eventlet.patcher.monkey_patch(all=False, socket=True, thread=True) + # NOTE(sileht): + # monkey-patching thread is required by python-keystoneclient; + # monkey-patching select is required by oslo.messaging pika driver + # if thread is monkey-patched. + eventlet.patcher.monkey_patch(all=False, socket=True, select=True, + thread=True) eventlet_debug = config_true_value(conf.get('eventlet_debug', 'no')) eventlet.debug.hub_exceptions(eventlet_debug) wsgi_logger = NullLogger() diff --git a/swift/container/updater.py b/swift/container/updater.py index 4703a5a04e..f2cd8f3328 100644 --- a/swift/container/updater.py +++ b/swift/container/updater.py @@ -143,7 +143,8 @@ class ContainerUpdater(Daemon): pid2filename[pid] = tmpfilename else: signal.signal(signal.SIGTERM, signal.SIG_DFL) - patcher.monkey_patch(all=False, socket=True, thread=True) + patcher.monkey_patch(all=False, socket=True, select=True, + thread=True) self.no_changes = 0 self.successes = 0 self.failures = 0 @@ -177,7 +178,7 @@ class ContainerUpdater(Daemon): """ Run the updater once. """ - patcher.monkey_patch(all=False, socket=True, thread=True) + patcher.monkey_patch(all=False, socket=True, select=True, thread=True) self.logger.info(_('Begin container update single threaded sweep')) begin = time.time() self.no_changes = 0 diff --git a/swift/obj/updater.py b/swift/obj/updater.py index 87c21c397f..9bf4ef19a3 100644 --- a/swift/obj/updater.py +++ b/swift/obj/updater.py @@ -94,7 +94,8 @@ class ObjectUpdater(Daemon): pids.append(pid) else: signal.signal(signal.SIGTERM, signal.SIG_DFL) - patcher.monkey_patch(all=False, socket=True, thread=True) + patcher.monkey_patch(all=False, socket=True, select=True, + thread=True) self.successes = 0 self.failures = 0 forkbegin = time.time() diff --git a/test/unit/common/test_wsgi.py b/test/unit/common/test_wsgi.py index c062762f93..f39f215499 100644 --- a/test/unit/common/test_wsgi.py +++ b/test/unit/common/test_wsgi.py @@ -380,6 +380,7 @@ class TestWSGI(unittest.TestCase): _eventlet.hubs.use_hub.assert_called_with(utils.get_hub()) _eventlet.patcher.monkey_patch.assert_called_with(all=False, socket=True, + select=True, thread=True) _eventlet.debug.hub_exceptions.assert_called_with(False) self.assertTrue(_wsgi.server.called) @@ -468,6 +469,7 @@ class TestWSGI(unittest.TestCase): _eventlet.hubs.use_hub.assert_called_with(utils.get_hub()) _eventlet.patcher.monkey_patch.assert_called_with(all=False, socket=True, + select=True, thread=True) _eventlet.debug.hub_exceptions.assert_called_with(False) self.assertTrue(_wsgi.server.called) @@ -520,6 +522,7 @@ class TestWSGI(unittest.TestCase): _eventlet.hubs.use_hub.assert_called_with(utils.get_hub()) _eventlet.patcher.monkey_patch.assert_called_with(all=False, socket=True, + select=True, thread=True) _eventlet.debug.hub_exceptions.assert_called_with(True) self.assertTrue(mock_server.called)