Fix a race-condition SbyProc that could truncate output
authorJannis Harder <me@jix.one>
Wed, 13 Jul 2022 13:54:24 +0000 (15:54 +0200)
committerJannis Harder <me@jix.one>
Wed, 13 Jul 2022 14:01:49 +0000 (16:01 +0200)
Present for a long time, but was not easy to hit. Some of my work in
progress changes made this much more likely and running the complete
test suite in parallel had a good chance of reproducing this for at
least one of the tests.

sbysrc/sby_core.py

index 372cbebf098d550aa86d4f0e9eae6f59fe40cb70..391fb16a33db35b5d9430fabc6b9bc4aeda2ca83 100644 (file)
@@ -183,17 +183,12 @@ class SbyProc:
             self.running = True
             return
 
-        while True:
-            outs = self.p.stdout.readline().decode("utf-8")
-            if len(outs) == 0: break
-            if outs[-1] != '\n':
-                self.linebuffer += outs
-                break
-            outs = (self.linebuffer + outs).strip()
-            self.linebuffer = ""
-            self.handle_output(outs)
+        self.read_output()
 
         if self.p.poll() is not None:
+            # The process might have written something since the last time we checked
+            self.read_output()
+
             if not self.silent:
                 self.task.log(f"{self.info}: finished (returncode={self.p.returncode})")
             self.task.update_proc_stopped(self)
@@ -231,6 +226,17 @@ class SbyProc:
                 next_proc.poll()
             return
 
+    def read_output(self):
+        while True:
+            outs = self.p.stdout.readline().decode("utf-8")
+            if len(outs) == 0: break
+            if outs[-1] != '\n':
+                self.linebuffer += outs
+                break
+            outs = (self.linebuffer + outs).strip()
+            self.linebuffer = ""
+            self.handle_output(outs)
+
 
 class SbyAbort(BaseException):
     pass