Move eventlet patch before call to loadapp

Ran into an eventlet bug[0] while integration Swift/Barbican
in TripleO. It is very similar to a previous bug related
to keystonemiddleware[1]. Suggestion from urllib3[2] is to
patch eventlet "as early as possible". Traceback[3] shows that
urllib3 is being imported before the eventlet patch, so moved
the patch to before the loadapp call.

[0] - http://paste.openstack.org/show/658046/
[1] - https://bugs.launchpad.net/swift/+bug/1662473
[2] - https://github.com/shazow/urllib3/issues/1104
[3] - https://gist.github.com/thiagodasilva/12dad7dc4f940b046dd0863b6f82a78b

Change-Id: I74e580f31349bdefd187cc5d6770a7041a936bef
This commit is contained in:
Thiago da Silva 2018-02-08 18:18:15 -05:00
parent 6b9098eead
commit c9410c7dd4
2 changed files with 15 additions and 18 deletions

View File

@ -430,7 +430,6 @@ 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())
utils.eventlet_monkey_patch()
eventlet_debug = config_true_value(conf.get('eventlet_debug', 'no'))
eventlet.debug.hub_exceptions(eventlet_debug)
wsgi_logger = NullLogger()
@ -905,6 +904,9 @@ def run_wsgi(conf_path, app_section, *args, **kwargs):
else:
strategy = WorkersStrategy(conf, logger)
# patch event before loadapp
utils.eventlet_monkey_patch()
# Ensure the configuration and application can be loaded before proceeding.
global_conf = {'log_name': log_name}
if 'global_conf_callback' in kwargs:

View File

@ -475,7 +475,6 @@ class TestWSGI(unittest.TestCase):
'modify_wsgi_pipeline'), \
mock.patch('swift.common.wsgi.wsgi') as _wsgi, \
mock.patch('swift.common.wsgi.eventlet') as _wsgi_evt, \
mock.patch('swift.common.utils.eventlet') as _utils_evt, \
mock.patch('swift.common.wsgi.inspect'):
conf = wsgi.appconfig(conf_file)
logger = logging.getLogger('test')
@ -485,10 +484,6 @@ class TestWSGI(unittest.TestCase):
_wsgi.HttpProtocol.default_request_version)
self.assertEqual(30, _wsgi.WRITE_TIMEOUT)
_wsgi_evt.hubs.use_hub.assert_called_with(utils.get_hub())
_utils_evt.patcher.monkey_patch.assert_called_with(all=False,
socket=True,
select=True,
thread=True)
_wsgi_evt.debug.hub_exceptions.assert_called_with(False)
self.assertTrue(_wsgi.server.called)
args, kwargs = _wsgi.server.call_args
@ -562,7 +557,6 @@ class TestWSGI(unittest.TestCase):
'modify_wsgi_pipeline'), \
mock.patch('swift.common.wsgi.wsgi') as _wsgi, \
mock.patch('swift.common.wsgi.eventlet') as _wsgi_evt, \
mock.patch('swift.common.utils.eventlet') as _utils_evt, \
mock.patch.dict('os.environ', {'TZ': ''}), \
mock.patch('swift.common.wsgi.inspect'), \
mock.patch('time.tzset'):
@ -576,10 +570,6 @@ class TestWSGI(unittest.TestCase):
_wsgi.HttpProtocol.default_request_version)
self.assertEqual(30, _wsgi.WRITE_TIMEOUT)
_wsgi_evt.hubs.use_hub.assert_called_with(utils.get_hub())
_utils_evt.patcher.monkey_patch.assert_called_with(all=False,
socket=True,
select=True,
thread=True)
_wsgi_evt.debug.hub_exceptions.assert_called_with(False)
self.assertTrue(_wsgi.server.called)
args, kwargs = _wsgi.server.call_args
@ -617,7 +607,6 @@ class TestWSGI(unittest.TestCase):
with mock.patch('swift.proxy.server.Application.'
'modify_wsgi_pipeline'), \
mock.patch('swift.common.wsgi.wsgi') as _wsgi, \
mock.patch('swift.common.utils.eventlet') as _utils_evt, \
mock.patch('swift.common.wsgi.eventlet') as _wsgi_evt:
mock_server = _wsgi.server
_wsgi.server = lambda *args, **kwargs: mock_server(
@ -630,10 +619,6 @@ class TestWSGI(unittest.TestCase):
_wsgi.HttpProtocol.default_request_version)
self.assertEqual(30, _wsgi.WRITE_TIMEOUT)
_wsgi_evt.hubs.use_hub.assert_called_with(utils.get_hub())
_utils_evt.patcher.monkey_patch.assert_called_with(all=False,
socket=True,
select=True,
thread=True)
_wsgi_evt.debug.hub_exceptions.assert_called_with(True)
self.assertTrue(mock_server.called)
args, kwargs = mock_server.call_args
@ -777,12 +762,17 @@ class TestWSGI(unittest.TestCase):
mock.patch.object(wsgi, 'drop_privileges'), \
mock.patch.object(wsgi, 'loadapp', _loadapp), \
mock.patch.object(wsgi, 'capture_stdio'), \
mock.patch.object(wsgi, 'run_server'):
mock.patch.object(wsgi, 'run_server'), \
mock.patch('swift.common.utils.eventlet') as _utils_evt:
wsgi.run_wsgi('conf_file', 'app_section',
global_conf_callback=_global_conf_callback)
self.assertEqual(calls['_global_conf_callback'], 1)
self.assertEqual(calls['_loadapp'], 1)
_utils_evt.patcher.monkey_patch.assert_called_with(all=False,
socket=True,
select=True,
thread=True)
def test_run_server_success(self):
calls = defaultdict(lambda: 0)
@ -802,11 +792,16 @@ class TestWSGI(unittest.TestCase):
mock.patch.object(wsgi, 'drop_privileges'), \
mock.patch.object(wsgi, 'loadapp', _loadapp), \
mock.patch.object(wsgi, 'capture_stdio'), \
mock.patch.object(wsgi, 'run_server'):
mock.patch.object(wsgi, 'run_server'), \
mock.patch('swift.common.utils.eventlet') as _utils_evt:
rc = wsgi.run_wsgi('conf_file', 'app_section')
self.assertEqual(calls['_initrp'], 1)
self.assertEqual(calls['_loadapp'], 1)
self.assertEqual(rc, 0)
_utils_evt.patcher.monkey_patch.assert_called_with(all=False,
socket=True,
select=True,
thread=True)
@mock.patch('swift.common.wsgi.run_server')
@mock.patch('swift.common.wsgi.WorkersStrategy')