[master 1/1] Check that the transaction process is still alive

vpodzime installerbot-noreply at redhat.com
Tue Mar 24 12:35:47 UTC 2015


From: Vratislav Podzimek <vpodzime at redhat.com>

If it terminates really badly (e.g. with SIGSEGV), it doesn't report any error,
just doesn't put anything to the queue. So instead of just blindly waiting on
the queue forever, check that the process is still alive if we don't get any
message in long time interval.
---
 src/pylorax/ltmpl.py | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py
index 1abbfc8..3b58798 100644
--- a/src/pylorax/ltmpl.py
+++ b/src/pylorax/ltmpl.py
@@ -40,6 +40,7 @@
 import struct
 import dnf
 import multiprocessing
+import Queue
 
 class LoraxTemplate(object):
     def __init__(self, directories=None):
@@ -519,6 +520,25 @@ def do_transaction(base, queue):
                 logger.error("The transaction process has ended abruptly: %s", e)
                 queue.put(('quit', str(e)))
 
+        def get_token_checked(process, queue):
+            """Try to get token from queue checking that process is still alive"""
+
+            try:
+                # wait at most a minute for the token
+                (token, msg) = queue.get(timeout=60)
+            except Queue.Empty:
+                if process.is_alive():
+                    try:
+                        # process still alive, give it 2 minutes more
+                        (token, msg) = queue.get(timeout=120)
+                    except Queue.Empty:
+                        # waited for 3 minutes and got nothing
+                        raise Exception("The transaction process got stuck somewhere")
+                else:
+                    raise Exception("The transaction process has ended abruptly")
+
+            return (token, msg)
+
         try:
             logger.info("Checking dependencies")
             self.dbo.resolve()
@@ -543,12 +563,14 @@ def do_transaction(base, queue):
         msgout = output.LoraxOutput()
         process = multiprocessing.Process(target=do_transaction, args=(self.dbo, queue))
         process.start()
-        (token, msg) = queue.get()
+        (token, msg) = get_token_checked(process, queue)
+
         while token not in ('post', 'quit'):
             if token == 'install':
                 logging.info("%s", msg)
                 msgout.writeline(msg)
-            (token, msg) = queue.get()
+            (token, msg) = get_token_checked(process, queue)
+
         if token == 'quit':
             logger.error("Transaction failed.")
             raise Exception("Transaction failed")


-- 
To view this commit on github, visit https://github.com/rhinstaller/lorax/commit/bd411bfd8ea9c92775bd496bfd5a30c50be765de


More information about the anaconda-patches mailing list