1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

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 <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
This commit is contained in:
Joe Guo 2017-09-15 16:13:26 +12:00 committed by Andrew Bartlett
parent 8ed3cac9e5
commit 5dc773a5b0
2 changed files with 8 additions and 7 deletions

View 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,

View File

@ -1 +0,0 @@
^samba.tests.blackbox.check_output