From: Joe Guo Date: Fri, 15 Sep 2017 04:13:26 +0000 (+1200) Subject: python: use communicate to fix Popen deadlock X-Git-Tag: samba-4.5.15~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd200ea5d2fb7e3948fae8fbeb114de557a14313;p=thirdparty%2Fsamba.git python: use communicate to fix Popen deadlock `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 Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Thu Oct 19 09:27:16 CEST 2017 on sn-devel-144 (cherry picked from commit 5dc773a5b00834c7a53130a73a48f49048bd55e8) Autobuild-User(v4-5-test): Stefan Metzmacher Autobuild-Date(v4-5-test): Tue Nov 14 14:35:22 CET 2017 on sn-devel-144 --- diff --git a/python/samba/tests/__init__.py b/python/samba/tests/__init__.py index a629fa59423..6960c0ca3ae 100644 --- a/python/samba/tests/__init__.py +++ b/python/samba/tests/__init__.py @@ -798,20 +798,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,