Blob Blame History Raw
From 17bcd2bcdb8de4818b361582ac4d833ff324f4ff Mon Sep 17 00:00:00 2001
From: "Bryn M. Reeves" <bmr@redhat.com>
Date: Mon, 10 Sep 2018 18:06:00 +0100
Subject: [PATCH] [utilities] wait until AsyncReader p.poll() returns None

On some systems the pipe used by the AsyncReader() class and the
sos_get_command_output() function may still be open at the time
the p.poll() call returns. At this time the command exit status
is undefined, leading to errors and collection failures for code
that tests the command's exit code.

Wait explicitly until poll() returns None to avoid this.

Resolves: #1417

Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
---
 sos/utilities.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sos/utilities.py b/sos/utilities.py
index d112e15a..25e10429 100644
--- a/sos/utilities.py
+++ b/sos/utilities.py
@@ -155,7 +155,8 @@ def sos_get_command_output(command, timeout=300, stderr=False,
 
         reader = AsyncReader(p.stdout, sizelimit, binary)
         stdout = reader.get_contents()
-        p.poll()
+        while p.poll() == None:
+            pass
 
     except OSError as e:
         if e.errno == errno.ENOENT:
-- 
2.17.1