python: use communicate to fix Popen deadlock
authorJoe Guo <joeg@catalyst.net.nz>
Fri, 15 Sep 2017 04:13:26 +0000 (16:13 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 19 Oct 2017 07:27:15 +0000 (09:27 +0200)
`Popen.wait()` will deadlock when using stdout=PIPE and/or stderr=PIPE and the
child process generates large output to a pipe such that it blocks waiting for
the OS pipe buffer to accept more data. Use communicate() to avoid that.

Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Thu Oct 19 09:27:16 CEST 2017 on sn-devel-144

python/samba/tests/__init__.py
selftest/knownfail.d/python-tests [deleted file]

index d012113cda682e73f17cb74f29edd6f86a0743c7..d634acab236e32430fd141bcdfedf47d878e533e 100644 (file)
@@ -326,20 +326,22 @@ class BlackboxTestCase(TestCaseInTempDir):
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE,
                              shell=True)
-        retcode = p.wait()
+        stdoutdata, stderrdata = p.communicate()
+        retcode = p.returncode
         if retcode != expected:
             raise BlackboxProcessError(retcode,
                                        line,
-                                       p.stdout.read(),
-                                       p.stderr.read())
+                                       stdoutdata,
+                                       stderrdata)
 
     def check_output(self, line):
         line = self._make_cmdline(line)
         p = subprocess.Popen(line, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, close_fds=True)
-        retcode = p.wait()
+        stdoutdata, stderrdata = p.communicate()
+        retcode = p.returncode
         if retcode:
-            raise BlackboxProcessError(retcode, line, p.stdout.read(), p.stderr.read())
-        return p.stdout.read()
+            raise BlackboxProcessError(retcode, line, stdoutdata, stderrdata)
+        return stdoutdata
 
 
 def connect_samdb(samdb_url, lp=None, session_info=None, credentials=None,
diff --git a/selftest/knownfail.d/python-tests b/selftest/knownfail.d/python-tests
deleted file mode 100644 (file)
index 754fed5..0000000
+++ /dev/null
@@ -1 +0,0 @@
-^samba.tests.blackbox.check_output