From 9fe5a99acddb6ab47eda8f0bbd214c78719fee65 Mon Sep 17 00:00:00 2001 From: Sam Morrison Date: Wed, 18 Dec 2019 15:38:14 +1100 Subject: [PATCH] Eventlet monkey patching should be as early as possible We were seeing infinite recursion opening an ssl socket when running various combinations of python3, eventlet, and urllib3. It is not clear exactly what combination of versions are affected, but for background there is an example of this issue documented here: https://github.com/eventlet/eventlet/issues/371 (Commit message copied in part from nova commit 3c5e2b0e9fac985294a949852bb8c83d4ed77e04) Change-Id: I76fed9e80a7f848a0f6b37c25dd035844c75a6ee --- murano/cmd/__init__.py | 14 ++++++++++++++ murano/cmd/api.py | 9 --------- murano/cmd/cfapi.py | 9 --------- murano/cmd/engine.py | 9 --------- murano/monkey_patch.py | 25 +++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 27 deletions(-) create mode 100644 murano/monkey_patch.py diff --git a/murano/cmd/__init__.py b/murano/cmd/__init__.py index e69de29bb..a9bd720ac 100644 --- a/murano/cmd/__init__.py +++ b/murano/cmd/__init__.py @@ -0,0 +1,14 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import murano.monkey_patch # noqa diff --git a/murano/cmd/api.py b/murano/cmd/api.py index 91c17cb06..6383c97cc 100644 --- a/murano/cmd/api.py +++ b/murano/cmd/api.py @@ -18,8 +18,6 @@ import os import sys -import eventlet - from oslo_concurrency import processutils from oslo_config import cfg from oslo_log import log as logging @@ -36,13 +34,6 @@ from murano.common import wsgi CONF = cfg.CONF -if os.name == 'nt': - # eventlet monkey patching causes subprocess.Popen to fail on Windows - # when using pipes due to missing non blocking I/O support - eventlet.monkey_patch(os=False) -else: - eventlet.monkey_patch() - # If ../murano/__init__.py exists, add ../ to Python search path, so that # it will override what happens to be installed in /usr/(local/)lib/python... root = os.path.join(os.path.abspath(__file__), os.pardir, os.pardir, os.pardir) diff --git a/murano/cmd/cfapi.py b/murano/cmd/cfapi.py index 9bfd922e4..29504cdbb 100644 --- a/murano/cmd/cfapi.py +++ b/murano/cmd/cfapi.py @@ -17,8 +17,6 @@ import os import sys -import eventlet - from oslo_config import cfg from oslo_log import log as logging from oslo_service import service @@ -32,13 +30,6 @@ from murano.common import wsgi CONF = cfg.CONF -if os.name == 'nt': - # eventlet monkey patching causes subprocess.Popen to fail on Windows - # when using pipes due to missing non blocking I/O support - eventlet.monkey_patch(os=False) -else: - eventlet.monkey_patch() - # If ../murano/__init__.py exists, add ../ to Python search path, so that # it will override what happens to be installed in /usr/(local/)lib/python... root = os.path.join(os.path.abspath(__file__), os.pardir, os.pardir, os.pardir) diff --git a/murano/cmd/engine.py b/murano/cmd/engine.py index 260af903a..6a8592be3 100644 --- a/murano/cmd/engine.py +++ b/murano/cmd/engine.py @@ -17,8 +17,6 @@ import os import sys -import eventlet - from oslo_concurrency import processutils from oslo_log import log as logging from oslo_service import service @@ -29,13 +27,6 @@ from murano.common import engine CONF = config.CONF -if os.name == 'nt': - # eventlet monkey patching causes subprocess.Popen to fail on Windows - # when using pipes due to missing non blocking I/O support - eventlet.monkey_patch(os=False) -else: - eventlet.monkey_patch() - # If ../murano/__init__.py exists, add ../ to Python search path, so that # it will override what happens to be installed in /usr/(local/)lib/python... root = os.path.join(os.path.abspath(__file__), os.pardir, os.pardir, os.pardir) diff --git a/murano/monkey_patch.py b/murano/monkey_patch.py new file mode 100644 index 000000000..28ec5f60c --- /dev/null +++ b/murano/monkey_patch.py @@ -0,0 +1,25 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +import os + +import eventlet + + +if os.name == 'nt': + # eventlet monkey patching causes subprocess.Popen to fail on Windows + # when using pipes due to missing non blocking I/O support + eventlet.monkey_patch(os=False) +else: + eventlet.monkey_patch()