diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c010743614..cf94d9c938 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -36,6 +36,10 @@ Fixed Contributed by Nick Maludy (@nmaludy Encore Technologies) +* Fixed a bug where a python3 sensor using ssl needs to be monkey patched earlier. See also #4832, #4975 and gevent/gevent#1016 (bug fix) #4976 + + Contributed by @punkrokk + Removed ~~~~~~~ diff --git a/st2actions/st2actions/cmd/actionrunner.py b/st2actions/st2actions/cmd/actionrunner.py index fce750190c..cf6c079a9e 100644 --- a/st2actions/st2actions/cmd/actionrunner.py +++ b/st2actions/st2actions/cmd/actionrunner.py @@ -15,6 +15,7 @@ # Monkey patching should be done as early as possible. # See http://eventlet.net/doc/patching.html#monkeypatching-the-standard-library from __future__ import absolute_import + from st2common.util.monkey_patch import monkey_patch monkey_patch() diff --git a/st2actions/st2actions/cmd/st2notifier.py b/st2actions/st2actions/cmd/st2notifier.py index b6a5cb664b..b2990e78a9 100644 --- a/st2actions/st2actions/cmd/st2notifier.py +++ b/st2actions/st2actions/cmd/st2notifier.py @@ -13,13 +13,16 @@ # limitations under the License. from __future__ import absolute_import + +from st2common.util.monkey_patch import monkey_patch +monkey_patch() + import os import sys from st2common import log as logging from st2common.service_setup import setup as common_setup from st2common.service_setup import teardown as common_teardown -from st2common.util.monkey_patch import monkey_patch from st2actions.notifier import config from st2actions.notifier import notifier @@ -27,8 +30,6 @@ 'main' ] -monkey_patch() - LOG = logging.getLogger(__name__) diff --git a/st2actions/st2actions/cmd/st2resultstracker.py b/st2actions/st2actions/cmd/st2resultstracker.py index c1614fc358..4269a3bf7c 100644 --- a/st2actions/st2actions/cmd/st2resultstracker.py +++ b/st2actions/st2actions/cmd/st2resultstracker.py @@ -13,13 +13,16 @@ # limitations under the License. from __future__ import absolute_import + +from st2common.util.monkey_patch import monkey_patch +monkey_patch() + import os import sys from st2common import log as logging from st2common.service_setup import setup as common_setup from st2common.service_setup import teardown as common_teardown -from st2common.util.monkey_patch import monkey_patch from st2actions.resultstracker import config from st2actions.resultstracker import resultstracker @@ -28,8 +31,6 @@ ] -monkey_patch() - LOG = logging.getLogger(__name__) diff --git a/st2auth/st2auth/cmd/api.py b/st2auth/st2auth/cmd/api.py index 10f46a4d61..cc5eebaca4 100644 --- a/st2auth/st2auth/cmd/api.py +++ b/st2auth/st2auth/cmd/api.py @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +from st2common.util.monkey_patch import monkey_patch +monkey_patch() + import eventlet import os import sys @@ -22,7 +25,6 @@ from st2common import log as logging from st2common.service_setup import setup as common_setup from st2common.service_setup import teardown as common_teardown -from st2common.util.monkey_patch import monkey_patch from st2auth import config config.register_opts() @@ -34,7 +36,6 @@ 'main' ] -monkey_patch() LOG = logging.getLogger(__name__) diff --git a/st2common/bin/paramiko_ssh_evenlets_tester.py b/st2common/bin/paramiko_ssh_evenlets_tester.py index 5086209461..fcd77a0d8c 100755 --- a/st2common/bin/paramiko_ssh_evenlets_tester.py +++ b/st2common/bin/paramiko_ssh_evenlets_tester.py @@ -15,15 +15,16 @@ from __future__ import absolute_import + +from st2common.util.monkey_patch import monkey_patch +monkey_patch() + import argparse import os import pprint -from st2common.util.monkey_patch import monkey_patch from st2common.ssh.parallel_ssh import ParallelSSHClient -monkey_patch() - def main(user, pkey, password, hosts_str, cmd, file_path, dir_path, delete_dir): hosts = hosts_str.split(",") diff --git a/st2exporter/st2exporter/cmd/st2exporter_starter.py b/st2exporter/st2exporter/cmd/st2exporter_starter.py index 8c853985e3..f7877d8ac0 100644 --- a/st2exporter/st2exporter/cmd/st2exporter_starter.py +++ b/st2exporter/st2exporter/cmd/st2exporter_starter.py @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +from st2common.util.monkey_patch import monkey_patch +monkey_patch() + import os import sys @@ -20,13 +23,11 @@ from st2common.service_setup import teardown as common_teardown from st2exporter import config from st2exporter import worker -from st2common.util.monkey_patch import monkey_patch __all__ = [ 'main' ] -monkey_patch() LOG = logging.getLogger(__name__) diff --git a/st2reactor/st2reactor/cmd/garbagecollector.py b/st2reactor/st2reactor/cmd/garbagecollector.py index 65908f6684..a2deabf890 100644 --- a/st2reactor/st2reactor/cmd/garbagecollector.py +++ b/st2reactor/st2reactor/cmd/garbagecollector.py @@ -14,6 +14,9 @@ from __future__ import absolute_import +from st2common.util.monkey_patch import monkey_patch +monkey_patch() + import os import sys @@ -23,7 +26,6 @@ from st2common.logging.misc import get_logger_name_for_module from st2common.service_setup import setup as common_setup from st2common.service_setup import teardown as common_teardown -from st2common.util.monkey_patch import monkey_patch from st2common.constants.exit_codes import FAILURE_EXIT_CODE from st2reactor.garbage_collector import config from st2reactor.garbage_collector.base import GarbageCollectorService @@ -32,8 +34,6 @@ 'main' ] -monkey_patch() - LOGGER_NAME = get_logger_name_for_module(sys.modules[__name__]) LOG = logging.getLogger(LOGGER_NAME) diff --git a/st2reactor/st2reactor/cmd/rulesengine.py b/st2reactor/st2reactor/cmd/rulesengine.py index af103b839f..ab3debd5be 100644 --- a/st2reactor/st2reactor/cmd/rulesengine.py +++ b/st2reactor/st2reactor/cmd/rulesengine.py @@ -13,6 +13,10 @@ # limitations under the License. from __future__ import absolute_import + +from st2common.util.monkey_patch import monkey_patch +monkey_patch() + import os import sys @@ -20,12 +24,9 @@ from st2common.logging.misc import get_logger_name_for_module from st2common.service_setup import setup as common_setup from st2common.service_setup import teardown as common_teardown -from st2common.util.monkey_patch import monkey_patch from st2reactor.rules import config from st2reactor.rules import worker -monkey_patch() - LOGGER_NAME = get_logger_name_for_module(sys.modules[__name__]) LOG = logging.getLogger(LOGGER_NAME) diff --git a/st2reactor/st2reactor/cmd/sensormanager.py b/st2reactor/st2reactor/cmd/sensormanager.py index 2244abb16e..205a1169bd 100644 --- a/st2reactor/st2reactor/cmd/sensormanager.py +++ b/st2reactor/st2reactor/cmd/sensormanager.py @@ -14,6 +14,9 @@ from __future__ import absolute_import +from st2common.util.monkey_patch import monkey_patch +monkey_patch() + import os import sys @@ -23,7 +26,6 @@ from st2common.logging.misc import get_logger_name_for_module from st2common.service_setup import setup as common_setup from st2common.service_setup import teardown as common_teardown -from st2common.util.monkey_patch import monkey_patch from st2common.exceptions.sensors import SensorNotFoundException from st2common.constants.exit_codes import FAILURE_EXIT_CODE from st2reactor.sensor import config @@ -34,7 +36,6 @@ 'main' ] -monkey_patch() LOGGER_NAME = get_logger_name_for_module(sys.modules[__name__]) LOG = logging.getLogger(LOGGER_NAME) diff --git a/st2reactor/st2reactor/cmd/timersengine.py b/st2reactor/st2reactor/cmd/timersengine.py index b91dcaefcb..ed162ed8ca 100644 --- a/st2reactor/st2reactor/cmd/timersengine.py +++ b/st2reactor/st2reactor/cmd/timersengine.py @@ -14,6 +14,9 @@ from __future__ import absolute_import +from st2common.util.monkey_patch import monkey_patch +monkey_patch() + import os import sys @@ -25,11 +28,9 @@ from st2common.logging.misc import get_logger_name_for_module from st2common.service_setup import setup as common_setup from st2common.service_setup import teardown as common_teardown -from st2common.util.monkey_patch import monkey_patch from st2reactor.timer import config from st2reactor.timer.base import St2Timer -monkey_patch() LOGGER_NAME = get_logger_name_for_module(sys.modules[__name__]) LOG = logging.getLogger(LOGGER_NAME) diff --git a/st2reactor/st2reactor/container/sensor_wrapper.py b/st2reactor/st2reactor/container/sensor_wrapper.py index 24cb606f91..14a78e5a35 100644 --- a/st2reactor/st2reactor/container/sensor_wrapper.py +++ b/st2reactor/st2reactor/container/sensor_wrapper.py @@ -14,6 +14,18 @@ from __future__ import absolute_import +# Note: We need to perform monkey patching in the worker. If we do it in +# the master process (gunicorn_config.py), it breaks tons of things +# including shutdown +# NOTE: It's important that we perform monkey patch as early as possible before any other modules +# are imported, otherwise SSL support for sensor clients won't work. +# See https://github.com/StackStorm/st2/issues/4832, https://github.com/StackStorm/st2/issues/4975 +# and https://github.com/gevent/gevent/issues/1016 +# for details. + +from st2common.util.monkey_patch import monkey_patch +monkey_patch() + import os import json import atexit @@ -36,7 +48,6 @@ from st2reactor.sensor.base import PollingSensor from st2reactor.sensor import config from st2common.services.datastore import SensorDatastoreService -from st2common.util.monkey_patch import monkey_patch from st2common.util.monkey_patch import use_select_poll_workaround __all__ = [ @@ -44,7 +55,6 @@ 'SensorService' ] -monkey_patch() use_select_poll_workaround(nose_only=False) diff --git a/st2reactor/tests/unit/test_sensor_wrapper.py b/st2reactor/tests/unit/test_sensor_wrapper.py index 2e8b1448e3..de314b5396 100644 --- a/st2reactor/tests/unit/test_sensor_wrapper.py +++ b/st2reactor/tests/unit/test_sensor_wrapper.py @@ -14,6 +14,9 @@ from __future__ import absolute_import +from st2common.util.monkey_patch import monkey_patch +monkey_patch() + import os import unittest2 @@ -21,8 +24,6 @@ import mock import eventlet -from st2common.util.monkey_patch import monkey_patch -monkey_patch() import st2tests.config as tests_config from st2tests.base import TESTS_CONFIG_PATH