Fixed error handling of launch of borg fails

Tue, 18 Sep 2018 18:10:03 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Tue, 18 Sep 2018 18:10:03 -0500
changeset 119
e5f29271089d
parent 118
aadd60a24bc8
child 120
109eaddc16e1

Fixed error handling of launch of borg fails

borgend/backup.py file | annotate | diff | comparison | revisions
--- a/borgend/backup.py	Mon Sep 17 19:48:02 2018 -0500
+++ b/borgend/backup.py	Tue Sep 18 18:10:03 2018 -0500
@@ -441,6 +441,13 @@
     def __do_launch(self, op, archive_or_repository,
                     common_params, op_params, paths=[]):
 
+        # Set up current_operation here so errors can be added to it in
+        # __main_thread if there is an exception
+        self.current_operation=op
+        # Update scheduled time to real starting time to schedule
+        # next run relative to this
+        self.current_operation.start_time=MonotonicTime.now()
+
         self.logger.debug('Creating BorgInstance')
 
         inst=BorgInstance(op.type, archive_or_repository,
@@ -462,17 +469,12 @@
         self.thread_log=t_log
         self.thread_res=t_res
         self.borg_instance=inst
-        self.current_operation=op
-        # Update scheduled time to real starting time to schedule
-        # next run relative to this
-        self.current_operation.start_time=MonotonicTime.now()
         # Reset error status when starting a new operation
         self.__update_status(State.ACTIVE)
 
         t_log.start()
         t_res.start()
 
-
     def __launch(self, op):
         self.logger.info("Launching '%s'" % str(op.type))
 
@@ -513,8 +515,6 @@
         return self._terminate or self._pause
 
     def __wait_finish(self):
-        current=self.current_operation
-
         # Wait for main logger thread to terminate, or for us to be terminated
         while not self._terminate_or_pause() and self.thread_res.is_alive():
             self._cond.release()
@@ -538,16 +538,24 @@
 
         if not self.borg_instance.wait():
             self.logger.error('Borg subprocess did not terminate')
-            curent.add_error(Errors.ERRORS)
+            self.current_operation.add_error(Errors.ERRORS)
+
+        self.thread_res=None
+        self.thread_log=None
+        self.borg_instance=None
+
+        self.__mark_current_finished()
+
+    def __mark_current_finished(self):
+        current=self.current_operation
+
+        assert(current)
 
         current.finish_time=MonotonicTime.now()
 
         self.previous_operation_of_type[current.type]=current
         self.previous_operation=current
         self.current_operation=None
-        self.thread_res=None
-        self.thread_log=None
-        self.borg_instance=None
 
     @protect_noreturn
     def __main_thread(self):
@@ -561,6 +569,10 @@
                         self.__main_thread_queue_and_launch()
                 except Exception as err:
                     self.logger.exception("Exception in backup '%s'" % self.backup_name)
+                    current=self.current_operation
+                    if current:
+                        current.add_error(Errors.ERRORS)
+                        self.__mark_current_finished()
                 finally:
                     self.__cleanup()
 

mercurial