Blame SOURCES/lvm2-2_03_03-lvmdbusd-Exit-daemon-when-unable-to-retrieve-state.patch

146ac4
 daemons/lvmdbusd/cfg.py   | 10 ++++++++++
146ac4
 daemons/lvmdbusd/fetch.py | 19 ++++++++++++++++++-
146ac4
 2 files changed, 28 insertions(+), 1 deletion(-)
146ac4
146ac4
diff --git a/daemons/lvmdbusd/cfg.py b/daemons/lvmdbusd/cfg.py
146ac4
index 771909f..be497d0 100644
146ac4
--- a/daemons/lvmdbusd/cfg.py
146ac4
+++ b/daemons/lvmdbusd/cfg.py
146ac4
@@ -87,3 +87,13 @@ blackbox = None
146ac4
 
146ac4
 # RequestEntry ctor
146ac4
 create_request_entry = None
146ac4
+
146ac4
+
146ac4
+def exit_daemon():
146ac4
+    """
146ac4
+    Exit the daemon cleanly
146ac4
+    :return:
146ac4
+    """
146ac4
+    if run and loop:
146ac4
+        run.value = 0
146ac4
+        loop.quit()
146ac4
diff --git a/daemons/lvmdbusd/fetch.py b/daemons/lvmdbusd/fetch.py
146ac4
index 69a4aae..e8f3521 100644
146ac4
--- a/daemons/lvmdbusd/fetch.py
146ac4
+++ b/daemons/lvmdbusd/fetch.py
146ac4
@@ -14,6 +14,7 @@ from . import cfg
146ac4
 from .utils import MThreadRunner, log_debug, log_error
146ac4
 import threading
146ac4
 import queue
146ac4
+import time
146ac4
 import traceback
146ac4
 
146ac4
 
146ac4
@@ -82,6 +83,8 @@ class StateUpdate(object):
146ac4
 
146ac4
 	@staticmethod
146ac4
 	def update_thread(obj):
146ac4
+		exception_count = 0
146ac4
+
146ac4
 		queued_requests = []
146ac4
 		while cfg.run.value != 0:
146ac4
 			# noinspection PyBroadException
146ac4
@@ -136,12 +139,26 @@ class StateUpdate(object):
146ac4
 				# wake up if we get an exception
146ac4
 				queued_requests = []
146ac4
 
146ac4
+				# We retrieved OK, clear exception count
146ac4
+				exception_count = 0
146ac4
+
146ac4
 			except queue.Empty:
146ac4
 				pass
146ac4
-			except Exception:
146ac4
+			except Exception as e:
146ac4
 				st = traceback.format_exc()
146ac4
 				log_error("update_thread exception: \n%s" % st)
146ac4
 				cfg.blackbox.dump()
146ac4
+				exception_count += 1
146ac4
+				if exception_count >= 5:
146ac4
+					for i in queued_requests:
146ac4
+						i.set_result(e)
146ac4
+
146ac4
+					log_error("Too many errors in update_thread, exiting daemon")
146ac4
+					cfg.exit_daemon()
146ac4
+
146ac4
+				else:
146ac4
+					# Slow things down when encountering errors
146ac4
+					time.sleep(1)
146ac4
 
146ac4
 	def __init__(self):
146ac4
 		self.lock = threading.RLock()