From ed07a5e849f193e4163b44061180983d09a39a61 Mon Sep 17 00:00:00 2001 From: JP Bourget Date: Fri, 26 Jun 2020 00:04:30 -0400 Subject: [PATCH 1/8] Fixes: #4875 monkeypatch st2 sensor earlier --- CHANGELOG.rst | 3 +++ st2reactor/st2reactor/container/sensor_wrapper.py | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a4c5d2232e..a8fda121d2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -30,6 +30,9 @@ Fixed * Fixed a bug in the example nginx HA template declared headers twice (bug fix) #4966 Contributed by @punkrokk +* Fixed a bug where a python3 sensor using ssl needs to be monkey patched earlier. #4975 ( See also + #4832 and https://github.com/gevent/gevent/issues/1016) + 3.2.0 - April 27, 2020 ---------------------- diff --git a/st2reactor/st2reactor/container/sensor_wrapper.py b/st2reactor/st2reactor/container/sensor_wrapper.py index 24cb606f91..a42a903340 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 important, 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) From d7dcc335ae26a74c73322530005332c6c6bb4bdd Mon Sep 17 00:00:00 2001 From: JP Bourget Date: Fri, 26 Jun 2020 09:36:24 -0400 Subject: [PATCH 2/8] changelog --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a8fda121d2..69c34c7195 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -31,7 +31,7 @@ Fixed Contributed by @punkrokk * Fixed a bug where a python3 sensor using ssl needs to be monkey patched earlier. #4975 ( See also - #4832 and https://github.com/gevent/gevent/issues/1016) + #4832 and https://github.com/gevent/gevent/issues/1016) Contributed by @punkrokk 3.2.0 - April 27, 2020 ---------------------- From 98cd0ddfdf7136d6babc6d03cde48da994ffedc4 Mon Sep 17 00:00:00 2001 From: JP Bourget Date: Fri, 26 Jun 2020 10:01:27 -0400 Subject: [PATCH 3/8] Fixes: #4832, moving monkey patching up on other services --- st2actions/st2actions/cmd/actionrunner.py | 1 + st2actions/st2actions/cmd/st2notifier.py | 7 ++++--- st2actions/st2actions/cmd/st2resultstracker.py | 7 ++++--- st2auth/st2auth/cmd/api.py | 5 +++-- st2common/bin/paramiko_ssh_evenlets_tester.py | 7 ++++--- st2exporter/st2exporter/cmd/st2exporter_starter.py | 5 +++-- st2reactor/st2reactor/cmd/garbagecollector.py | 5 +++-- st2reactor/st2reactor/cmd/rulesengine.py | 6 ++++-- st2reactor/st2reactor/cmd/sensormanager.py | 5 +++-- st2reactor/st2reactor/cmd/timersengine.py | 5 +++-- st2reactor/tests/unit/test_sensor_wrapper.py | 5 +++-- 11 files changed, 35 insertions(+), 23 deletions(-) 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..bd69131243 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,7 +34,6 @@ 'main' ] -monkey_patch() LOGGER_NAME = get_logger_name_for_module(sys.modules[__name__]) diff --git a/st2reactor/st2reactor/cmd/rulesengine.py b/st2reactor/st2reactor/cmd/rulesengine.py index af103b839f..6980a8409c 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,11 +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__]) 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/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 From 10df180720ad55c4d8cd5e355ac89ca6be2c13c9 Mon Sep 17 00:00:00 2001 From: JP Bourget Date: Mon, 29 Jun 2020 15:05:58 -0400 Subject: [PATCH 4/8] Update st2reactor/st2reactor/container/sensor_wrapper.py Co-authored-by: Jacob Floyd --- st2reactor/st2reactor/container/sensor_wrapper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2reactor/st2reactor/container/sensor_wrapper.py b/st2reactor/st2reactor/container/sensor_wrapper.py index a42a903340..14a78e5a35 100644 --- a/st2reactor/st2reactor/container/sensor_wrapper.py +++ b/st2reactor/st2reactor/container/sensor_wrapper.py @@ -18,7 +18,7 @@ # 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 important, otherwise SSL support for sensor clients won't work. +# 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 75d6ed73f34b39e447ca08ad417acf25d24d5ee6 Mon Sep 17 00:00:00 2001 From: JP Bourget Date: Tue, 30 Jun 2020 16:43:35 -0400 Subject: [PATCH 5/8] fix linting --- st2reactor/st2reactor/cmd/garbagecollector.py | 1 - st2reactor/st2reactor/cmd/rulesengine.py | 1 - 2 files changed, 2 deletions(-) diff --git a/st2reactor/st2reactor/cmd/garbagecollector.py b/st2reactor/st2reactor/cmd/garbagecollector.py index bd69131243..a2deabf890 100644 --- a/st2reactor/st2reactor/cmd/garbagecollector.py +++ b/st2reactor/st2reactor/cmd/garbagecollector.py @@ -35,7 +35,6 @@ ] - 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 6980a8409c..ab3debd5be 100644 --- a/st2reactor/st2reactor/cmd/rulesengine.py +++ b/st2reactor/st2reactor/cmd/rulesengine.py @@ -28,7 +28,6 @@ from st2reactor.rules import worker - LOGGER_NAME = get_logger_name_for_module(sys.modules[__name__]) LOG = logging.getLogger(LOGGER_NAME) From 5763e78c7e9715ab9ab97562d2a675af9ba374a4 Mon Sep 17 00:00:00 2001 From: JP Bourget Date: Wed, 15 Jul 2020 15:57:15 -0400 Subject: [PATCH 6/8] fix v3.2 Removed title overline --- CHANGELOG.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d80baa4ec2..7aa18d0286 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -37,7 +37,6 @@ Fixed * Fixed a bug where a python3 sensor using ssl needs to be monkey patched earlier. #4975 ( See also #4832 and https://github.com/gevent/gevent/issues/1016) Contributed by @punkrokk -======= Removed ~~~~~~~ From 8789cbc981bad4a7e7704166f0ef2873134d0c16 Mon Sep 17 00:00:00 2001 From: JP Bourget Date: Thu, 16 Jul 2020 10:59:55 -0400 Subject: [PATCH 7/8] Update CHANGELOG.rst Co-authored-by: Eugen C. --- CHANGELOG.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7aa18d0286..e691e876a6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -34,8 +34,9 @@ Fixed Contributed by Nick Maludy (@nmaludy Encore Technologies) -* Fixed a bug where a python3 sensor using ssl needs to be monkey patched earlier. #4975 ( See also - #4832 and https://github.com/gevent/gevent/issues/1016) Contributed by @punkrokk +* 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 ~~~~~~~ From f79b3df4447951778653f435536b019526a5df31 Mon Sep 17 00:00:00 2001 From: JP Bourget Date: Thu, 16 Jul 2020 11:00:04 -0400 Subject: [PATCH 8/8] Update CHANGELOG.rst Co-authored-by: Eugen C. --- CHANGELOG.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e691e876a6..842f7148d4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -45,7 +45,6 @@ Removed Contributed by Amanda McGuinness (@amanda11 Ammeon Solutions) - 3.2.0 - April 27, 2020 ----------------------