Skip to content

Instantly share code, notes, and snippets.

@fzipi
Created October 2, 2020 15:37
Show Gist options
  • Save fzipi/af135b5e1f78128ffdafff3f8240caa9 to your computer and use it in GitHub Desktop.
Save fzipi/af135b5e1f78128ffdafff3f8240caa9 to your computer and use it in GitHub Desktop.
Patch for zeromq problems in Salt
From 77d023b73b37ac4989aa4fd6ca119c62eeca7b97 Mon Sep 17 00:00:00 2001
From: Felipe Zipitria <fzipitria@perceptyx.com>
Date: Fri, 2 Oct 2020 12:33:08 -0300
Subject: [PATCH] fix(zeromq): backport zeromq patch
Signed-off-by: Felipe Zipitria <fzipitria@perceptyx.com>
---
salt/scripts.py | 21 ++++++++++++++++-----
salt/transport/zeromq.py | 14 ++++++++++++++
2 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/salt/scripts.py b/salt/scripts.py
index bf33496127..346f365146 100644
--- a/salt/scripts.py
+++ b/salt/scripts.py
@@ -432,11 +432,22 @@ def salt_call():
salt minion to run.
'''
import salt.cli.call
- if '' in sys.path:
- sys.path.remove('')
- client = salt.cli.call.SaltCall()
- _install_signal_handlers(client)
- client.run()
+
+ try:
+ from salt.transport import zeromq
+ except ImportError:
+ zeromq = None
+
+ try:
+ if "" in sys.path:
+ sys.path.remove("")
+ client = salt.cli.call.SaltCall()
+ _install_signal_handlers(client)
+ client.run()
+ finally:
+ if zeromq is not None:
+ zeromq.AsyncZeroMQReqChannel.force_close_all_instances()
+
def salt_run():
diff --git a/salt/transport/zeromq.py b/salt/transport/zeromq.py
index d7196c1a91..56bcbad762 100644
--- a/salt/transport/zeromq.py
+++ b/salt/transport/zeromq.py
@@ -212,6 +212,20 @@ class AsyncZeroMQReqChannel(salt.transport.client.ReqChannel):
kwargs={'io_loop': self._io_loop})
self._closing = False
+ @classmethod
+ def force_close_all_instances(cls):
+ """
+ Will force close all instances
+
+ ZMQ can hang on quit if left to deconstruct on its own.
+ This because is deconstructs out of order.
+
+ :return: None
+ """
+ for weak_dict in list(cls.instance_map.values()):
+ for instance in list(weak_dict.values()):
+ instance.close()
+
def close(self):
'''
Since the message_client creates sockets and assigns them to the IOLoop we have to
--
2.26.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment