From b716dbc9768bd6a0ef7d016a9c79e8759e383732 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 7 Sep 2020 10:31:36 +0200 Subject: [PATCH] python/tests/gpo: this should fix a Popen deadlock It is inspired by commit 5dc773a5b00834c7a53130a73a48f49048bd55e8 Author: Joe Guo Date: Fri Sep 15 16:13:26 2017 +1200 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 Signed-off-by: Stefan Metzmacher Reviewed-by: Andreas Schneider Reviewed-by: Noel Power --- python/samba/tests/gpo.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/python/samba/tests/gpo.py b/python/samba/tests/gpo.py index 43a4aacfc14..c8440929b11 100644 --- a/python/samba/tests/gpo.py +++ b/python/samba/tests/gpo.py @@ -54,23 +54,22 @@ def days2rel_nttime(val): sam_add = 10000000 return -(val * seconds * minutes * hours * sam_add) -def gpupdate_force(lp): +def gpupdate(lp, arg): gpupdate = lp.get('gpo update command') - gpupdate.append('--force') + gpupdate.append(arg) - return Popen(gpupdate, stdout=PIPE, stderr=PIPE).wait() + p = Popen(gpupdate, stdout=PIPE, stderr=PIPE) + stdoutdata, stderrdata = p.communicate() + return p.returncode -def gpupdate_unapply(lp): - gpupdate = lp.get('gpo update command') - gpupdate.append('--unapply') +def gpupdate_force(lp): + return gpupdate(lp, '--force') - return Popen(gpupdate, stdout=PIPE, stderr=PIPE).wait() +def gpupdate_unapply(lp): + return gpupdate(lp, '--unapply') def rsop(lp): - gpupdate = lp.get('gpo update command') - gpupdate.append('--rsop') - - return Popen(gpupdate, stdout=PIPE).wait() + return gpupdate(lp, '--rsop') def stage_file(path, data): dirname = os.path.dirname(path) -- 2.47.3